convert wmi to winbatch

Started by Orionbelt, November 06, 2013, 01:40:07 PM

Previous topic - Next topic

Orionbelt

hi all, i am having issue converting to winbatch (probably easy for someone)
=============================
' Connect into WMI and get current Asset Tag
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
   strPreAssetTag = objSMBIOS.SMBIOSAssetTag
   'For Testing
   wscript.echo "Asset Tag = " & strPreAssetTag
Next

==========================================
here what i did

Locator   = ObjectOpen("WbemScripting.SWbemLocator")
Service   = Locator.ConnectServer()
Security   = Service.Security_
Security.ImpersonationLevel    = 3

Class1               = "Win32_SystemEnclosure"
Instance1          = Service.InstancesOf(Class1)
hEnum1              = ObjectCollectionOpen(Instance1)
Obj1              = ObjectCollectionNext(hEnum1)

Foreach objSMBIOS in Obj1
   AssetTag = Obj1.SMBIOSAssetTag      ;ASSET TAG.
Next
====================================================

thax in advance

Deana

Here ya go:

Code (winbatch) Select
; Connect into WMI and get current Asset Tag
strComputer = '.'
objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" : strComputer : "\root\cimv2")
colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
ForEach objSMBIOS in colSMBIOS
   strPreAssetTag = objSMBIOS.SMBIOSAssetTag
   ;For Testing
   Pause( "Asset Tag = " , strPreAssetTag )
Next
Deana F.
Technical Support
Wilson WindowWare Inc.

Orionbelt


Deana

As you can see, converting any WMI VBScript to WinBatch is pretty straight forward...

  • Change ' comment  to ;
  • Remove all leading set commands.
  • Change + concatenation operator to :
  • Change 'For Each' to 'ForEach'
  • Replace wscript.echo with Pause(title,text) function
Just to name a few...
Deana F.
Technical Support
Wilson WindowWare Inc.

Orionbelt