Jump to content

Recommended Posts

Posted (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:

; 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 by jefhal
...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Posted

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" )
Endif

Not 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
  • 1 year later...
Posted

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.

Posted

Base on jefhal's code, I did some changes to fit freezer's request.

Wish can help.

#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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...