Jump to content

Convert vbs code to AutoIt


Recommended Posts

HELP!!!

Is there anyone out there who could help me convert the following vb code to AutoIt??? I'm trying to pull the Dell Service Tag # so that I can display it in a script. I found this little program but I have no idea how to work with Visual Basic code. All I am interested in is the Dell Service Tag, not the Username or Computer name...I can get all of that.

'Connect to WMI namespace
Dim objWshShell, colitems, objWMIservice, objitem, strUserName, strComputerName
Set objWshShell = CreateObject("WScript.Shell") 
strUserName = objWshShell.ExpandEnvironmentStrings("%USERNAME%") ' Locates Username
strComputerName = objWshShell.ExpandEnvironmentStrings("%COMPUTERNAME%") ' Locates Computer Name
Set objWMIservice = GetObject("winmgmts:\\.\root\cimv2")
set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)
For each objitem in colitems ' Locates Dell Service Tag
'Output
Wscript.echo " User Name: " & strUserName & vbcr _
& " Computer Name: " & strComputerName & vbcr _
& " Dell Service Tag: " & objitem.serialnumber
Next

Thanks in advance!

Edited by HockeyFan
Link to comment
Share on other sites

Suggest using http://www.autoitscript.com/forum/index.ph...amp;showfile=29

; 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_BIOS", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $strBiosCharacteristics = $objItem.BiosCharacteristics(0)
      $Output = $Output & "BiosCharacteristics: " & $strBiosCharacteristics & @CRLF
      $strBIOSVersion = $objItem.BIOSVersion(0)
      $Output = $Output & "BIOSVersion: " & $strBIOSVersion & @CRLF
      $Output = $Output & "BuildNumber: " & $objItem.BuildNumber & @CRLF
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $Output = $Output & "CodeSet: " & $objItem.CodeSet & @CRLF
      $Output = $Output & "CurrentLanguage: " & $objItem.CurrentLanguage & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "IdentificationCode: " & $objItem.IdentificationCode & @CRLF
      $Output = $Output & "InstallableLanguages: " & $objItem.InstallableLanguages & @CRLF
      $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
      $Output = $Output & "LanguageEdition: " & $objItem.LanguageEdition & @CRLF
      $strListOfLanguages = $objItem.ListOfLanguages(0)
      $Output = $Output & "ListOfLanguages: " & $strListOfLanguages & @CRLF
      $Output = $Output & "Manufacturer: " & $objItem.Manufacturer & @CRLF
      $Output = $Output & "Name: " & $objItem.Name & @CRLF
      $Output = $Output & "OtherTargetOS: " & $objItem.OtherTargetOS & @CRLF
      $Output = $Output & "PrimaryBIOS: " & $objItem.PrimaryBIOS & @CRLF
      $Output = $Output & "ReleaseDate: " & WMIDateStringToDate($objItem.ReleaseDate) & @CRLF
      $Output = $Output & "SerialNumber: " & $objItem.SerialNumber & @CRLF
      $Output = $Output & "SMBIOSBIOSVersion: " & $objItem.SMBIOSBIOSVersion & @CRLF
      $Output = $Output & "SMBIOSMajorVersion: " & $objItem.SMBIOSMajorVersion & @CRLF
      $Output = $Output & "SMBIOSMinorVersion: " & $objItem.SMBIOSMinorVersion & @CRLF
      $Output = $Output & "SMBIOSPresent: " & $objItem.SMBIOSPresent & @CRLF
      $Output = $Output & "SoftwareElementID: " & $objItem.SoftwareElementID & @CRLF
      $Output = $Output & "SoftwareElementState: " & $objItem.SoftwareElementState & @CRLF
      $Output = $Output & "Status: " & $objItem.Status & @CRLF
      $Output = $Output & "TargetOperatingSystem: " & $objItem.TargetOperatingSystem & @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_BIOS" )
Endif


Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

This doesn't return anything for me ('cause I'm not on a Dell, maybe), but it exits without errors, so it might work for you:

; Connect to WMI namespace
Dim $objWshShell, $colitems, $objWMIservice, $objitem, $strUserName, $strComputerName
$objWshShell = ObjCreate("WScript.Shell")
$strUserName = $objWshShell.ExpandEnvironmentStrings ("%USERNAME%") ; Locates Username
$strComputerName = $objWshShell.ExpandEnvironmentStrings ("%COMPUTERNAME%") ; Locates Computer Name
$objWMIservice = ObjGet("winmgmts:\\.\root\cimv2")
$colitems = $objWMIservice.ExecQuery ("Select * from Win32_BIOS", -1, 48)
For $objitem In $colitems ; Locates Dell Service Tag
    ; Output
    MsgBox(64, "Dell Asset Tag", " User Name: " & $strUserName & @CRLF _
             & " Computer Name: " & $strComputerName & @CRLF _
             & " Dell Service Tag: " & $objitem.serialnumber)
Next

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Developers

this works on my Dell

; Connect to WMI namespace
Dim $objWshShell, $colitems, $objWMIservice, $objitem
$objWshShell = ObjCreate("WScript.Shell")
$objWMIservice = ObjGet("winmgmts:\\.\root\cimv2")
$colitems = $objWMIservice.ExecQuery ("Select * from Win32_BIOS", "WQL", 48)
For $objitem In $colitems ; Locates Dell Service Tag
    ; Output
    MsgBox(64, "Dell Asset Tag", " User Name: " & @UserName & @CRLF _
             & " Computer Name: " & @ComputerName & @CRLF _
             & " Dell Service Tag: " & $objitem.serialnumber)
Next
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

This doesn't return anything for me ('cause I'm not on a Dell, maybe), but it exits without errors, so it might work for you:

; Connect to WMI namespace
Dim $objWshShell, $colitems, $objWMIservice, $objitem, $strUserName, $strComputerName
$objWshShell = ObjCreate("WScript.Shell")
$strUserName = $objWshShell.ExpandEnvironmentStrings ("%USERNAME%") ; Locates Username
$strComputerName = $objWshShell.ExpandEnvironmentStrings ("%COMPUTERNAME%") ; Locates Computer Name
$objWMIservice = ObjGet("winmgmts:\\.\root\cimv2")
$colitems = $objWMIservice.ExecQuery ("Select * from Win32_BIOS", -1, 48)
For $objitem In $colitems ; Locates Dell Service Tag
    ; Output
    MsgBox(64, "Dell Asset Tag", " User Name: " & $strUserName & @CRLF _
             & " Computer Name: " & $strComputerName & @CRLF _
             & " Dell Service Tag: " & $objitem.serialnumber)
Next

:)

Thanks PsaltyDS...but I get no output either. Thanks for your input thought.

Link to comment
Share on other sites

this works on my Dell

; Connect to WMI namespace
Dim $objWshShell, $colitems, $objWMIservice, $objitem
$objWshShell = ObjCreate("WScript.Shell")
$objWMIservice = ObjGet("winmgmts:\\.\root\cimv2")
$colitems = $objWMIservice.ExecQuery ("Select * from Win32_BIOS", "WQL", 48)
For $objitem In $colitems ; Locates Dell Service Tag
    ; Output
    MsgBox(64, "Dell Asset Tag", " User Name: " & @UserName & @CRLF _
             & " Computer Name: " & @ComputerName & @CRLF _
             & " Dell Service Tag: " & $objitem.serialnumber)
Next
JdeB,

AWESOME!! This is great! Thank you!! :)

Link to comment
Share on other sites

Thanks PsaltyDS...but I get no output either. Thanks for your input thought.

Just changing the -1 to "WQL" (ala JdeB) made it work for me too. Learn somethin' new every day...

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 2 months later...

this works on my Dell

; Connect to WMI namespace
Dim $objWshShell, $colitems, $objWMIservice, $objitem
$objWshShell = ObjCreate("WScript.Shell")
$objWMIservice = ObjGet("winmgmts:\\.\root\cimv2")
$colitems = $objWMIservice.ExecQuery ("Select * from Win32_BIOS", "WQL", 48)
For $objitem In $colitems ; Locates Dell Service Tag
    ; Output
    MsgBox(64, "Dell Asset Tag", " User Name: " & @UserName & @CRLF _
             & " Computer Name: " & @ComputerName & @CRLF _
             & " Dell Service Tag: " & $objitem.serialnumber)
Next

Can I put this info into a logon script to gather info of all my systems into a general txt or ini file??

Please info.

Link to comment
Share on other sites

Can I put this info into a logon script to gather info of all my systems into a general txt or ini file??

Please info.

Why not? Did you try it?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

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