spudw2k Posted August 16, 2007 Share Posted August 16, 2007 Is it possible to use a variable in place of property or method of an object?example. I want to do a WMI query and pull variable results.$host = "localhost"$strWMIQuery = "SELECT * FROM Win32_ComputerSystem"$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $host & "\root\cimv2")$colItems = $objWMIService.ExecQuery ($strWMIQuery)For $objItem in $colItemsmsgbox(0,"Hostname",$objItem.Name) ;<--- .Name is what I'd like to be able replace with a variableNext Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 16, 2007 Share Posted August 16, 2007 (edited) Is it possible to use a variable in place of property or method of an object?example. I want to do a WMI query and pull variable results.$host = "localhost"$strWMIQuery = "SELECT * FROM Win32_ComputerSystem"$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $host & "\root\cimv2")$colItems = $objWMIService.ExecQuery ($strWMIQuery)For $objItem in $colItemsmsgbox(0,"Hostname",$objItem.Name) ;<--- .Name is what I'd like to be able replace with a variableNextThis is kind of a silly question... what happens when you run it...? And silly questions do not become less silly by liberal application of color tags... Edited August 16, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
spudw2k Posted August 16, 2007 Author Share Posted August 16, 2007 A message box with your hostname in it Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
lordofthestrings Posted August 17, 2007 Share Posted August 17, 2007 (edited) in short No, it's not possible to do this.. plus I would really disadvice this practise .. (not good coding and allow me to explain) a method (.Name) is allready the easiest discription of the action you want to perform with this object. the only thing you could achieve is add unnecessary code (meaning: complications) to your script. allow me to demonstrate using the Speech api. speak("this is steven hawkins, wazaaaaaaap") speak2("this is steven hawkins, wazaaaaaaap") Func speak($Text) $spApi = ObjCreate("SAPI.SpVoice") $spApi.Speak($Text) EndFunc ;speak($Text) Func speak2($Text) $x = "Speak" $spApi = ObjCreate("SAPI.SpVoice") $spApi.$x($Text) EndFunc ;speak($Text) if you remove the line that calls speak2() and remove the function (speak2) then the script works.. plus read the errormessage you get when you try running this code.. ==> Expected a "=" operator in assignment statement.: Edited August 17, 2007 by lordofthestrings Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 17, 2007 Share Posted August 17, 2007 (edited) A message box with your hostname in it Well, what I meant was: what happens when you replace .Name with a variable. I was only pointing out that it would be a very easy experiment to conduct and see the results. Looks like lordofthestrings did that for you already, though. EDIT: This works: $host = "localhost" $strWMIQuery = "SELECT * FROM Win32_ComputerSystem" $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $host & "\root\cimv2") $colItems = $objWMIService.ExecQuery ($strWMIQuery) $Property = 'Name' For $objItem In $colItems MsgBox(0, "Hostname", Execute('$objItem.' & $Property)) Next Edited August 17, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
lordofthestrings Posted August 17, 2007 Share Posted August 17, 2007 ok, that makes me shut up (for a short while again) Link to comment Share on other sites More sharing options...
weaponx Posted August 17, 2007 Share Posted August 17, 2007 This works for for me: speak("hello") speak2("hello") Func speak($Text) $spApi = ObjCreate("SAPI.SpVoice") $spApi.Speak($Text) EndFunc ;speak($Text) Func speak2($Text) $x = "Speak" $spApi = ObjCreate("SAPI.SpVoice") ;$spApi.$x($Text) Execute("$spApi." & $x & "($Text)") EndFunc ;speak($Text) Link to comment Share on other sites More sharing options...
NELyon Posted August 17, 2007 Share Posted August 17, 2007 (edited) Does this work for you? $method = "Name" $host = "localhost" $strWMIQuery = "SELECT * FROM Win32_ComputerSystem" $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $host & "\root\cimv2") $colItems = $objWMIService.ExecQuery ($strWMIQuery) For $objItem in $colItems msgbox(0,"Hostname",Execute("$objItem." & $method)) Next Not Tested, but should work in theory EDIT: Whoops, didn't see PsaltyDS' post... Edited August 17, 2007 by Senton-Bomb Link to comment Share on other sites More sharing options...
weaponx Posted August 17, 2007 Share Posted August 17, 2007 I don't really see a usefullness for this considering that an object has a static set of member functions. They are not dynamic. Link to comment Share on other sites More sharing options...
spudw2k Posted August 17, 2007 Author Share Posted August 17, 2007 Well the only reason i was hoping to do this was to be able to call a function and dynamically request particular data, which happens to be returned from a property. I think the main issue is i'm passing a string to the object. Thanks for the answer though. At least I didn't waste to much time trying to find the answer. Maybe I'll just have the function grab all the data I would need and just pick and choose what I need at the time. Thanks again. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
DaleHohm Posted August 17, 2007 Share Posted August 17, 2007 It sounds like you are giving up... did you misunderstand? An answer was provided... the key is the Execute function: $Name = "whatever-you-want" msgbox(0, "Hostname", Execute("$objItem." & $Name)) Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
spudw2k Posted August 17, 2007 Author Share Posted August 17, 2007 Holy crap, that works! Thanks That makes things easier. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
spudw2k Posted August 17, 2007 Author Share Posted August 17, 2007 (edited) Here's what I needed it for btw. expandcollapse popup#include <Array.au3> Local $oWMIService = _WMIService() ;Instantiate WMIService Object - Establish Connection If $oWMIService = 0 Then Exit ;If WMI Object failed to instantiate, Abort Script Local $sWMIQueryClass = "Win32_ComputerSystem" ;Declare WMI Class to Query Local $aWMIQueryFields[]= ["Name","Manufacturer","Model","Domain"] ;Declare Fields to Retrieve From WMI Class $aResults = _WMIQuery($oWMIService,$sWMIQueryClass,$aWMIQueryFields) ;Run WMI Query against WMIService Object $oWMIService = 0 ;Termninate WMIService Object _ArrayDisplay($aResults) ;Display Results Array Exit Func _WMIService($sHost = @ComputerName) ;Connect to WMI Service $oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sHost & "\root\cimv2") ;Create WMI Service Object If Not IsObj($oWMIService) Then Return SetError(1,0,0) ;If Obj Instantiation Failed, Error Out Return $oWMIService ;Return WMI Service Object EndFunc Func _WMIQuery($oWMIService,$sWMIQueryClass,$aWMIQueryFields) ;Perform WMI Query with Query String and Data Return Parameters If Not IsObj($oWMIService) Then Return SetError(1,0,0) ;If oWMIService is not a valid Object, Error Out If Not IsArray($aWMIQueryFields) Then Return SetError(2,0,0) ;If Query Fields is not a valid array, Error Out Local $aResults = $aWMIQueryFields ;Create Results Array _ArrayColInsert($aResults, 1) ;Add Dimension to Results Array to Hold Query Return Values Local $sWMIQuery = "SELECT " & _ArrayToString($aWMIQueryFields,",") & " FROM " & $sWMIQueryClass ;Create WMI Query String $oItems = $oWMIService.ExecQuery ($sWMIQuery) ;Execute query using WMI Service Object For $i = 0 to UBound($aWMIQueryFields) - 1 ;Loop through WMI Query Results For $oItem In $oItems $aResults[$i][1] = Execute("$oItem." & $aWMIQueryFields[$i]) ;Result Next Next Return $aResults ;Return Result Array EndFunc edit: optimized example Edited December 14, 2018 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF 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