Friendlybob4u Posted April 5, 2011 Posted April 5, 2011 Hello I'm a newbie at scripting but I was wondering if you guys can help me out. Probably be really easy for you guys. Im trying to query a local computer's wmi in Autoit to the get model name. The reason I am making this script is to run a specfic program according to the system model. This is example of my basic script: $objWMI = ObjGet("winmgmts:\\localhost\root\CIMV2") $objItems = $objWMI.ExecQuery ("SELECT * FROM Win32_ComputerSystem.Model") If $objItems = ("Optiplex 745") Then Run ("notepad.exe") Else MsgBox(0, "Warning", "This is not a Optiplex 745") EndIf This script does not work properly but if you pro's can point me in the right direction I would really apprechiate it.
sahsanu Posted April 6, 2011 Posted April 6, 2011 I've used the script "Scriptomatic.au3" (you should find it on C:\Program Files\AutoIt3\Examples\COM) and this could help you. ; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $model="" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $model=$objItem.Model Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystem" ) Endif If $model="Optiplex 745" Then Run ("notepad.exe") Else MsgBox(0, "Warning", "This is not an Optiplex 745") EndIf
Friendlybob4u Posted April 6, 2011 Author Posted April 6, 2011 Thanks for your help, but its still not working with WMI, any other suggestions I should try? When I complile and run this program I just get the "Warning", "This is not an Optiplex 745" message box. I am currently running this script on a 745. I've used the script "Scriptomatic.au3" (you should find it on C:\Program Files\AutoIt3\Examples\COM) and this could help you. ; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $model="" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $model=$objItem.Model Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystem" ) Endif If $model="Optiplex 745" Then Run ("notepad.exe") Else MsgBox(0, "Warning", "This is not an Optiplex 745") EndIf
MrMitchell Posted April 6, 2011 Posted April 6, 2011 Can you put a MsgBox inside here so it tells you what $model is in every step of the loop? For $objItem In $colItems $model=$objItem.Model MsgBox(0, "Model", $model) Next
spudw2k Posted April 6, 2011 Posted April 6, 2011 I would at least check top see what the value of $model is after running the query. 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
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