gr1fter Posted January 28, 2010 Posted January 28, 2010 Hello, 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: expandcollapse popup'WMI_Model.vbs '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" WScript.Quit End Select Next CommandShell = "cmd.exe /C " WshShell.Run(CommandShell + strScriptPath + strModelScript) WScript.Quit
gr1fter Posted January 29, 2010 Author Posted January 29, 2010 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") EndSwitch Next EndIf EndIf 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!
water Posted January 29, 2010 Posted January 29, 2010 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: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
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