Sign in to follow this  
Followers 0
Friendlybob4u

WMI Query

5 posts in this topic

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. :)

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0