jefhal Posted September 11, 2005 Posted September 11, 2005 (edited) This is somewhat obscure, but at least it shows one example of converting WMI script to AutoIT script semi-manually: I use a nice piece of found vbs code to get the Dell service tag of a computer. Since I do everything with AutoIT these days, I discovered a way, (thanks indirectly to AutoIT Scriptomatic), to convert the WMI code to AutoIT. Here's the commented code for beta 75: expandcollapse popup; Generated by AutoIt Scriptomatic ; Edited by Jeff Hall to handle a different case ; used the WMI method: objSMBIOS.SerialNumber to get Dell Service Tag ;;; ORIGINAL WMI SCRIPT THAT RETURNS THE SERVICE TAG OF A DELL COMPUTER: ;~ strComputer = "." ;~ Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") ;~ Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure") ;~ For Each objSMBIOS in colSMBIOS ;~ Wscript.Echo "Serial Number: " & objSMBIOS.SerialNumber ;~ Next ;;; AutoIT SCRIPT, with comments, that returns the service tag of a Dell computer: $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF ;WMI format: Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") ;WMI format: Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure") $colSMBIOS = $objWMIService.ExecQuery("Select * from Win32_SystemEnclosure") If IsObj($colSMBIOS) then ;WMI format: For Each objSMBIOS in colSMBIOS For $objSMBIOS In $colSMBIOS ;WMI: Wscript.Echo "Serial Number: " & objSMBIOS.SerialNumber $Output = $Output & "Caption: " & $objSMBIOS.SerialNumber & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Process" ) Endif Edited September 11, 2005 by jefhal ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
jefhal Posted September 11, 2005 Author Posted September 11, 2005 I discovered a way, (thanks indirectly to AutoIT Scriptomatic), to convert the WMI code to AutoIT.Note to self: "Don't ever think you are smarter than the AutoIT developers."Or, I could have just used AutoIT Scriptomatic to do the entire coding for me. Directly from AutoIT Scriptomatic:; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "Caption: " & $objItem.Caption & @CRLF $Output = $Output & "Description: " & $objItem.Description & @CRLF $Output = $Output & "IdentifyingNumber: " & $objItem.IdentifyingNumber & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "SKUNumber: " & $objItem.SKUNumber & @CRLF $Output = $Output & "UUID: " & $objItem.UUID & @CRLF $Output = $Output & "Vendor: " & $objItem.Vendor & @CRLF $Output = $Output & "Version: " & $objItem.Version & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystemProduct" ) EndifNot only does this get the Service Tag, but it also does the dishes... :"> ...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
freezer Posted August 14, 2007 Posted August 14, 2007 Is it possible to add this to a login script. saving this info to a ini or txt file?? in this file i would like the: pc name pc type service tag please help.
wh97 Posted August 21, 2007 Posted August 21, 2007 Base on jefhal's code, I did some changes to fit freezer's request. Wish can help. expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.1.1.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems IniWrite ( "C:\Info.ini", "HW Info", "PC Name", @ComputerName ) IniWrite ( "C:\Info.ini", "HW Info", "PC Type", $objItem.Name ) IniWrite ( "C:\Info.ini", "HW Info", "Service Tag", $objItem.IdentifyingNumber ) Next Else IniWrite ( "C:\Info.ini", "HW Info", "PC Name", @ComputerName ) IniWrite ( "C:\Info.ini", "HW Info", "PC Type", "Not Found" ) IniWrite ( "C:\Info.ini", "HW Info", "Service Tag", "Not Found" ) Endif
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