Mechaflash Posted October 22, 2012 Share Posted October 22, 2012 (edited) Trying to manipulate Win32 classes and I want to insert values to pull from the class via an array. I'm having a problem with accomplishing this. (Check arrows) I also tried $obj.Eval($aValues[$y]) and it doesn't work in that manner. Is there another way to accomplish this? Local $aValues[2] = ["Name","Description"] $aReturn = _Win32Call("Win32_Product", $aValues) _ArrayDisplay($aReturn) Func _Win32Call(Const $sClass, Const $aValues) Local $objWMIService, $colObj, $obj, $sReturn, $i = -1, $x = 0 Local $aReturn[5][UBound($aValues) - 1] $objWMIService = ObjGet("winmgmts:localhostrootCIMV2") $colObj = $objWMIService.ExecQuery ("SELECT * FROM " & $sClass) For $obj in $colObj $i+=1 $x+=1 If IsInt($x / 5) Then ReDim $aReturn[$x + 5][UBound($aValues) - 1] For $y = 0 To UBound($aValues) - 1 $aReturn[$i][$y] = $obj.$aValues[$y] ; <<<<<<<<<<<<<<<<<<<<<<<<<< HERE Next Next For $i = UBound($aReturn) - 6 To UBound($aReturn) - 1 For $y = 0 To UBound($aValues) - 1 If $aReturn[$i][$y] = "" Then $fDel = True Else $fDel = False ExitLoop EndIf Next If $fDel Then _ArrayDelete($aReturn, $i) Next Return $aReturn EndFunc Edited October 22, 2012 by Mechaflash Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
jdelaney Posted October 22, 2012 Share Posted October 22, 2012 might want to you a switch case instead IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
water Posted October 22, 2012 Share Posted October 22, 2012 (edited) Please have a look at the source of the There is a method that returns a collection of all properties. Loop through the properties and select the matches.I think this is the relevant code part:For $objProperty in $objClass.Properties_() ; Must use (), because method ends with an underscore If $objProperty.IsArray = True Then $strScriptCode = $strScriptCode & " $str" & $objProperty.Name & " = $objItem." & $objProperty.Name & "(0)" & @CRLF $strScriptCode = $strScriptCode & " $Output = $Output & " & $strRowStart & $objProperty.Name & $strColumnSeparator & Chr(34) & " & $str" & $objProperty.Name & $strRowEnd & @CRLF ElseIf $objProperty.CIMTYPE = 101 Then $bHasDates = True $strScriptCode = $strScriptCode & " $Output = $Output & " & $strRowStart & $objProperty.Name & $strColumnSeparator & Chr(34) & " & WMIDateStringToDate($objItem." & $objProperty.Name & ")" & $strRowEnd & @CRLF Else $strScriptCode = $strScriptCode & " $Output = $Output & " & $strRowStart & $objProperty.Name & $strColumnSeparator & Chr(34) & " & $objItem." & $objProperty.Name & $strRowEnd & @CRLF EndIf NextStarts at line 369. Edited October 22, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Mechaflash Posted October 22, 2012 Author Share Posted October 22, 2012 My goal was to just be able to insert a class and pick exactly which properties to view as to reduce the time it takes to query the information. I could tap into Scriptomatic.au3 and parse the information without a GUI, instead using direct, programmatic inputs. I was hoping to be able to do it via $obj.$aValues[$y] so that it would be a lot faster to receive a return, and I'd be able to tailor the command specifically for the needs of the operator. Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
Mechaflash Posted October 22, 2012 Author Share Posted October 22, 2012 might want to you a switch case insteadI don't see how/why/where I would use a switch case in my script? If you mean doing a switch/case with the class properties... you be crazy. Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
water Posted October 22, 2012 Share Posted October 22, 2012 I think this should work: $aReturn[$i][$y] = Execute("$obj." & $aValues[$y]) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Mechaflash Posted October 22, 2012 Author Share Posted October 22, 2012 I think this should work: $aReturn[$i][$y] = Execute("$obj." & $aValues[$y]) I believe this is the key. I'm getting an error with my array but I don't think it pertains to that statement. I'll post with a follow-up after I get it working 100% Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
Mechaflash Posted October 22, 2012 Author Share Posted October 22, 2012 (edited) Awesome! Thanks water. Got it working. Local $aValues[2] = ["Name","Description"] $aReturn = _Win32Call("Win32_Product", $aValues) _ArrayDisplay($aReturn) Func _Win32Call(Const $sClass, Const $aValues) Local $objWMIService, $colObj, $obj, $sReturn, $i = -1, $x = 0 Local $aReturn[5][UBound($aValues)] $objWMIService = ObjGet("winmgmts:localhostrootCIMV2") $colObj = $objWMIService.ExecQuery ("SELECT * FROM " & $sClass) For $obj in $colObj $i+=1 $x+=1 If IsInt($x / 5) Then ReDim $aReturn[$x + 5][UBound($aValues)] For $y = 0 To UBound($aValues) - 1 $aReturn[$i][$y] = Execute("$obj." & $aValues[$y]) Next Next For $i = UBound($aReturn) - 6 To UBound($aReturn) - 1 For $y = 0 To UBound($aValues) - 1 If $aReturn[$i][$y] = "" Then $fDel = True Else $fDel = False ExitLoop EndIf Next If $fDel Then _ArrayDelete($aReturn, $i) Next Return $aReturn EndFunc Edited October 22, 2012 by Mechaflash Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
water Posted October 22, 2012 Share Posted October 22, 2012 This example script works fine for me and returns the correct result: ; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" Local $aValues[2] = ["Name", "Description"] $Output = "" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems ConsoleWrite(Execute("$objItem." & $aValues[0]) & @LF) ConsoleWrite(Execute("$objItem." & $aValues[1]) & @LF) Next Else MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_Processor") EndIfIntel® Core™2 Duo CPU E7400 @ 2.80GHz Intel64 Family 6 Model 23 Stepping 10 My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted October 22, 2012 Share Posted October 22, 2012 Oopps, too slow! Glad you got it working My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now