WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WMI
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

WMI Reference

Keywords: 	 Microsoft WMI API Reference	 WMI Collections

The 2002E version of Winbatch has a few new functions for enumerating OLE collections. This includes access to all the WMI information on the computer. WMI stands for 'Windows Management Instrumentation'.

Here's the reference from Microsoft:

WMI SDK
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394582(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394572(v=vs.85).aspx

WMI Scripting Primers WMI Scripting Primer: Part 1 WMI Scripting Primer: Part 2 WMI Scripting Primer: Part 3

And here are some Winbatch examples:

For details on the Win32_Bios WMI Class, see:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394077(v=vs.85).aspx

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


BiosSet = Service.InstancesOf("Win32_Bios")

hEnum = ObjectCollectionOpen(BiosSet)

While 1
  Bios = ObjectCollectionNext(hEnum)
  If Bios == 0 Then Break
  Message("Bios.SerialNumber", Bios.SerialNumber)
  ObjectClose(Bios)
EndWhile

ObjectCollectionClose(hEnum)

ObjectClose(BiosSet)


;set MemorySet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strPC & "/root/cimv2")
;.ExecQuery("select TotalPhysicalMemory, TotalVirtualMemory, TotalPageFileSpace from Win32_LogicalMemoryConfiguration")
;for each Memory in MemorySet
;strRAM = FormatNumber(Memory.TotalPhysicalMemory/1024,1) & " Mbytes"
;strVir = FormatNumber(Memory.TotalVirtualMemory/1024,1) & " Mbytes"
;strPage = FormatNumber(Memory.TotalPageFileSpace/1024,1) & " Mbytes"
;Next
 
MemSet = Service.InstancesOf("Win32_LogicalMemoryConfiguration")

hEnum = ObjectCollectionOpen(MemSet)

While 1
  Mem = ObjectCollectionNext(hEnum)
  If Mem == 0 Then Break
  Message("Mem.TotalPhysicalMemory", Mem.TotalPhysicalMemory)
  Message("Mem.TotalVirtualMemory", Mem.TotalVirtualMemory)
  Message("Mem.TotalPageFileSpace", Mem.TotalPageFileSpace)
  ObjectClose(Mem)
EndWhile

ObjectCollectionClose(hEnum)

ObjectClose(MemSet)



;set ProSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strPC & "/root/cimv2")
;.ExecQuery("select Name, MaxClockSpeed from Win32_Processor")
;for each Pro in ProSet
;strProc = Pro.Name
;strSpeed = Pro.MaxClockSpeed
;Next

ProcSet = Service.InstancesOf("Win32_Processor")

hEnum = ObjectCollectionOpen(ProcSet)

While 1
  Proc = ObjectCollectionNext(hEnum)
  If Proc == 0 Then Break
  Message("Proc.MaxClockSpeed", Proc.MaxClockSpeed)
  ObjectClose(Proc)
EndWhile

ObjectCollectionClose(hEnum)

ObjectClose(ProcSet)



;set DiskSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strPC & "/root/cimv2")
;.ExecQuery("select DeviceID, FileSystem, Size, FreeSpace from Win32_LogicalDisk where DeviceID = 'C:' and DriveType = '3'")
;
;ReDim strDisk(RowNum,4)
;for each Disk in DiskSet
;strDisk(RowNum,DEV_ID)= Disk.DeviceID
;strDisk(RowNum,FSYS)= Disk.FileSystem
;strDisk(RowNum,DSIZE)= FormatNumber(Disk.Size/2^30,1) & " Gbytes"
;strDisk(RowNum,FSPACE)= FormatNumber(Disk.FreeSpace/2^30,1) & " Gbytes"
;strDisk(RowNum,USPACE)= FormatNumber((Disk.Size-Disk.FreeSpace)/2^30,1) & " Gbytes"
;
;Call AddLineToXLS(strCompName, strSN, strDisk(RowNum,DEV_ID), strDisk(RowNum,FSYS), strDisk(RowNum,DSIZE), strDisk(RowNum,FSPACE), strDisk(RowNum,USPACE), strRAM, strVir, strPage, strOS, strSP, strProdID, strNIC, strIP, strMask, strGate, strMAC, strProc, strSpeed)
;Next

:fszork
DiskSet = Service.InstancesOf("Win32_LogicalDisk")

hEnum = ObjectCollectionOpen(DiskSet)

While 1
  disk = ObjectCollectionNext(hEnum)
  If disk == 0 Then Break
  Message("disk.DeviceID", disk.DeviceID)
  ;Special Note.  If disks are bigger than 2GB, the HUGEMATH extender must be used
  ;with to do arithmetic on these numbers.
  Message("disk.FileSystem", disk.FileSystem)
  Message("disk.Size", disk.Size)
  Message("disk.FreeSpace", disk.FreeSpace)
  ObjectClose(disk)
EndWhile

ObjectCollectionClose(hEnum)

ObjectClose(DiskSet)


;set OSSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strPC & "/root/cimv2")
;.ExecQuery("select Caption, CSDVersion, SerialNumber from Win32_OperatingSystem")
;for each OS in OSSet
;strOS = OS.Caption
;strSP = OS.CSDVersion
;strProdID = OS.SerialNumber
;Next


OSSet = Service.InstancesOf("Win32_OperatingSystem")

hEnum = ObjectCollectionOpen(OSSet)

While 1
  OS = ObjectCollectionNext(hEnum)
  If OS == 0 Then Break
  Message("OS.Caption", OS.Caption)
  Message("OS.CSDVersion", OS.CSDVersion)
  Message("OS.SerialNumber", OS.SerialNumber)
  ObjectClose(OS)
EndWhile

ObjectCollectionClose(hEnum)

ObjectClose(OSSet)


;set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strPC & "/root/cimv2")
;.ExecQuery("select ServiceName, IPAddress, IPSubnet, DefaultIPGateway, MACAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
;
;Count = 0
;for each IPConfig in IPConfigSet
;Count = Count + 1
;Next
;ReDim sName(Count - 1)
;ReDim sIP(Count - 1)
;ReDim sMask(Count - 1)
;ReDim sGate(Count - 1)
;ReDim sMAC(Count - 1)
;Count = 0
;
;for each IPConfig in IPConfigSet
;sName(Count) = IPConfig.ServiceName(0)
;strNIC = sName(Count)
;sIP(Count) = IPConfig.IPAddress(0)
;strIP = sIP(Count)
;sMask(Count) = IPConfig.IPSubnet(0)
;strMask = sMask(Count)
;sGate(Count) = IPConfig.DefaultIPGateway(0)
;strGate = sGate(Count)
;sMAC(Count) = IPConfig.MACAddress(0)
;strMAC = sMAC(Count)
;Count = Count + 1
;Next

IPSet = Service.InstancesOf("Win32_NetworkAdapterConfiguration")

hEnum = ObjectCollectionOpen(IPSet)

While 1
  IPConfig = ObjectCollectionNext(hEnum)
  If IPConfig == 0 Then Break
  if IPConfig.IPEnabled == 0 then continue
  Message("IPConfig.ServiceName", IPConfig.ServiceName)


  Message("IPConfig.IPAddress", IPConfig.IPAddress(0) )

  Message("IPConfig.IPSubnet", IPConfig.IPSubnet(0) )


  Message("IPConfig.MACAddress", IPConfig.MACAddress)
  ObjectClose(IPConfig)
EndWhile

ObjectCollectionClose(hEnum)

ObjectClose(IPSet)




ObjectClose(Security)
ObjectClose(Service)
ObjectClose(Locator)

Article ID:   W15354
File Created: 2013:01:29:08:48:00
Last Updated: 2013:01:29:08:48:00