Jump to content
Sign in to follow this  

Help me convert vb script to auto it?

Recommended Posts



I would like to take the functionality in this vb code and do the exact in autoit. I seem to be lost when doing WMI stuff in auto it. Any help or advice to lead me in the right direction would very much appreciated.

Here is the VB Script:

'January 2006, Rob D., hdsurvivor.blogspot.com
'Determine model of PC, and run appropriate post-imaging script

Dim strComputer '. is the local PC
Dim WshShell 'the windows script shell
Dim strModelScript 'name of the script to run
Dim CommandShell 'the command shell to use
Dim strQuery 'the WMI Query to run
Dim colCompSys 'the win32_ComputerSystem collection
Dim strScriptPath 'path to build scripts
DIM PCModel 'the trimmed string with the model name

strComputer = "."
strScriptPath = "C:\WINDOWS\system32\Scripts"
Set WshShell = WScript.CreateObject("WScript.Shell")
strQuery="SELECT * from Win32_ComputerSystem"
Set colCompSys=GetObject("WinMgmts://" & strComputer & "/root/cimv2").ExecQuery(strQuery)

For Each WMIProperty in colCompSys
PCModel = TRIM(WMIProperty.Model)
Select Case PCModel
Case "HP ProBook 6445b"
strModelScript = "6445b.exe"
WScript.Echo "Configuring HP ProBook 6445b"
Case "HP rp5700 Business System"
strModelScript = "5700.exe"
WScript.Echo "Configuring HP RP5700"
Case Else
WScript.Echo "The PC Model is " & PCModel & VBCrLf & " There is no configuration for this model"
End Select

CommandShell = "cmd.exe /C "
WshShell.Run(CommandShell + strScriptPath + strModelScript)


Share this post

Link to post
Share on other sites

I've never used WMI in AutoIt before, but I think I've got it. This script basically produces the same results that your vbscript does, on my PC.

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w1 -w2 -w3 -w4 -w5 -w6
Local $sPC = ".", $sScript, $model

Local $oWMIService = ObjGet("WinMgmts:\\" & $sPC & "\root\CIMV2")
If IsObj($oWMIService) Then
    Local $colItems = $oWMIService.ExecQuery('SELECT * FROM Win32_ComputerSystem', 'WQL', 0x30)
    If IsObj($colItems) Then
        For $oItem In $colItems
            $model = $oItem.Model
            Switch $model
                Case "HP ProBook 6445b"
                    MsgBox(0, "", "Configuring HP ProBook 6445b")
                    Run(@ComSpec & " /c " & "C:\WINDOWS\system32\Scripts\6445b.exe")
                Case "HP rp5700 Business System"
                    MsgBox(0, "", "Configuring HP RP5700")
                    Run(@ComSpec & " /c " & "C:\WINDOWS\system32\Scripts\5700.exe")
                Case Else
                    Exit MsgBox(0, "", "The PC Model is " & $model & @CRLF & " There is no configuration for this model")

It works great thank you very much! WMI is still very hazy to me. But I really appreciate your time and from your script I can see what i need to do for the future. Thanks again!

Share this post

Link to post
Share on other sites

If you need more WMI in the future please have a look at the AutoIt implementation of Scriptomatic.

It let's you all kind of WMI queries, test the results and genereates Autoit source code for you.

My UDFs and Tutorials:


Active Directory (NEW 2017-04-18 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version - Download - General Help & Support

ADO - Wiki


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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.