JonnyThunder Posted June 27, 2008 Share Posted June 27, 2008 Hello,Im using various WMI queries to extract information on a PC. I'd have a bit of code like this...$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BaseBoard", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then Dim $data_motherboard[5] For $objItem In $colItems $data_motherboard[0] = $objItem.Manufacturer $data_motherboard[1] = $objItem.Model $data_motherboard[2] = $objItem.Product $data_motherboard[3] = $objItem.SerialNumber $data_motherboard[4] = $objItem.Version Next Else $data_motherboard = False EndifIs there any way to use a variable in place of the object properties? So instead of.... $objitem.ManufacturerI'm after something like... $objitem.$mypropertynameI've tried it as above, but it doesn't work. Is there any way of doing this?Thanks,JT Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 27, 2008 Share Posted June 27, 2008 Good coffee this morning: #include <Array.au3> $sProperty = "Manufacturer" $objWMIService = ObjGet("WINMGMTS:\\.\ROOT\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BaseBoard", "WQL") Dim $data_motherboard[5] If IsObj($colItems) then For $objItem In $colItems $sData = Eval("objItem." & $sProperty) $data_motherboard[0] = $objItem.Manufacturer ; $data_motherboard[0] = $objItem.Manufacturer $data_motherboard[1] = $objItem.Model $data_motherboard[2] = $objItem.Product $data_motherboard[3] = $objItem.SerialNumber $data_motherboard[4] = $objItem.Version Next Else $data_motherboard[0] = False Endif _ArrayDisplay($data_motherboard, "$data_motherboard") 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...
JonnyThunder Posted June 30, 2008 Author Share Posted June 30, 2008 (edited) This script does work, but not sure what you mean by it! It's still pulling information from those properties without variables. Edited June 30, 2008 by JonnyThunder Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 30, 2008 Share Posted June 30, 2008 This script does work, but not sure what you mean by it! It's still pulling information from those properties without variables. My mistake, posted the wrong version. I was trying various things with Eval(), Execute(), etc. Here is the one that worked and should have been posted to begin with: #include <Array.au3> $sProperty = "Manufacturer" $objWMIService = ObjGet("WINMGMTS:\\.\ROOT\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BaseBoard", "WQL") Dim $data_motherboard[5] If IsObj($colItems) then For $objItem In $colItems $sData = Execute("$objItem." & $sProperty) $data_motherboard[0] = $sData ; $data_motherboard[0] = $objItem.Manufacturer $data_motherboard[1] = $objItem.Model $data_motherboard[2] = $objItem.Product $data_motherboard[3] = $objItem.SerialNumber $data_motherboard[4] = $objItem.Version Next Else $data_motherboard[0] = False Endif _ArrayDisplay($data_motherboard, "$data_motherboard") 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...
JonnyThunder Posted July 1, 2008 Author Share Posted July 1, 2008 Ahh, thats brilliant. i actually went down the same way of thinking and tried eval, but not execute. Thanks for your post PsaltyDS. Mucho appreciate-o. /nicotine required. 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