WMIGEN - Generator of templates for WMI classes (DISPATCH)

Started by José Roca, July 12, 2011, 12:26:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
This tool generates templates for WMI classes using the WMI dispatch interfaces.

Code produced for the Win32_BIOS class of the root\CIMV2 namespace.


' ########################################################################################
' WMI Template
' Namespace = root\CIMV2
' WMI Class = Win32_BIOS
' ########################################################################################

#COMPILE EXE
#DIM ALL
#INCLUDE "WMI.INC"

' ========================================================================================
' Retrieves the values of all of the properties of the Win32_BIOS class
' ========================================================================================
SUB WMI_Win32_BIOS (OPTIONAL BYVAL bstrComputer AS WSTRING)

   LOCAL hr AS LONG                                  ' // HRESULT
   LOCAL pService AS ISWbemServices                  ' // Services object
   LOCAL pObjectSet AS ISWbemObjectSet               ' // ISWbemObjectSet interface
   LOCAL pEnum AS IEnumVariant                       ' // Generic collection's enumerator reference
   LOCAL bstrDisplayName AS WSTRING                  ' // Display name
   LOCAL bstrQuery AS WSTRING                        ' // Query string
   LOCAL oItem AS DISPATCH                           ' // Generic object variable
   LOCAL vItem AS VARIANT                            ' // Generic object variant
   LOCAL vRes AS VARIANT                             ' // General purpose variant

   ' // Variants to store the property values
   LOCAL vBiosCharacteristics AS VARIANT             ' // Array - Unsigned 16-bit integer
   LOCAL vBIOSVersion AS VARIANT                     ' // Array - String
   LOCAL vBuildNumber AS VARIANT                     ' // String
   LOCAL vCaption AS VARIANT                         ' // String
   LOCAL vCodeSet AS VARIANT                         ' // String
   LOCAL vCurrentLanguage AS VARIANT                 ' // String
   LOCAL vDescription AS VARIANT                     ' // String
   LOCAL vIdentificationCode AS VARIANT              ' // String
   LOCAL vInstallableLanguages AS VARIANT            ' // Unsigned 16-bit integer
   LOCAL vInstallDate AS VARIANT                     ' // Date/time value
   LOCAL vLanguageEdition AS VARIANT                 ' // String
   LOCAL vListOfLanguages AS VARIANT                 ' // Array - String
   LOCAL vManufacturer AS VARIANT                    ' // String
   LOCAL vName AS VARIANT                            ' // String
   LOCAL vOtherTargetOS AS VARIANT                   ' // String
   LOCAL vPrimaryBIOS AS VARIANT                     ' // Boolean value
   LOCAL vReleaseDate AS VARIANT                     ' // Date/time value
   LOCAL vSerialNumber AS VARIANT                    ' // String
   LOCAL vSMBIOSBIOSVersion AS VARIANT               ' // String
   LOCAL vSMBIOSMajorVersion AS VARIANT              ' // Unsigned 16-bit integer
   LOCAL vSMBIOSMinorVersion AS VARIANT              ' // Unsigned 16-bit integer
   LOCAL vSMBIOSPresent AS VARIANT                   ' // Boolean value
   LOCAL vSoftwareElementID AS VARIANT               ' // String
   LOCAL vSoftwareElementState AS VARIANT            ' // Unsigned 16-bit integer
   LOCAL vStatus AS VARIANT                          ' // String
   LOCAL vTargetOperatingSystem AS VARIANT           ' // Unsigned 16-bit integer
   LOCAL vVersion AS VARIANT                         ' // String

   ' // Connect to WMI using a moniker
   IF LEN(bstrComputer) = 0 THEN bstrComputer = "."
   bstrDisplayName = "winmgmts:{impersonationLevel=impersonate}!\\" & bstrComputer & "\root\CIMV2"
   pService = WmiGetObject(bstrDisplayName)
   IF ISNOTHING(pService) THEN EXIT SUB

   ' // Execute a query to get a reference to the collection of objects
   bstrQuery = "SELECT * FROM Win32_BIOS
   pObjectSet = pService.ExecQuery(bstrQuery, "WQL", %wbemFlagReturnImmediately)
   IF ISNOTHING(pObjectSet) THEN EXIT SUB
   ' // Retrieve a reference to the collection's enumerator
   pEnum = pObjectSet.NewEnum_
   IF ISNOTHING(pEnum) THEN EXIT SUB
   ' // Iterate through the collection of objects
   DO
      ' // Retrieve a reference to the next object in the collection
      hr = pEnum.Next(1, vItem, BYVAL %NULL)
      IF hr <> %S_OK THEN EXIT DO
      ' // Assign the VT_DISPATCH variant to the object variable
      oItem = vItem : vItem = EMPTY
      IF ISNOTHING(oItem) THEN EXIT DO
      ' // Retrieve the values of the properties
      OBJECT GET oItem.BiosCharacteristics TO vBiosCharacteristics
      OBJECT GET oItem.BIOSVersion TO vBIOSVersion
      OBJECT GET oItem.BuildNumber TO vBuildNumber
      OBJECT GET oItem.Caption TO vCaption
      OBJECT GET oItem.CodeSet TO vCodeSet
      OBJECT GET oItem.CurrentLanguage TO vCurrentLanguage
      OBJECT GET oItem.Description TO vDescription
      OBJECT GET oItem.IdentificationCode TO vIdentificationCode
      OBJECT GET oItem.InstallableLanguages TO vInstallableLanguages
      OBJECT GET oItem.InstallDate TO vInstallDate
      OBJECT GET oItem.LanguageEdition TO vLanguageEdition
      OBJECT GET oItem.ListOfLanguages TO vListOfLanguages
      OBJECT GET oItem.Manufacturer TO vManufacturer
      OBJECT GET oItem.Name TO vName
      OBJECT GET oItem.OtherTargetOS TO vOtherTargetOS
      OBJECT GET oItem.PrimaryBIOS TO vPrimaryBIOS
      OBJECT GET oItem.ReleaseDate TO vReleaseDate
      OBJECT GET oItem.SerialNumber TO vSerialNumber
      OBJECT GET oItem.SMBIOSBIOSVersion TO vSMBIOSBIOSVersion
      OBJECT GET oItem.SMBIOSMajorVersion TO vSMBIOSMajorVersion
      OBJECT GET oItem.SMBIOSMinorVersion TO vSMBIOSMinorVersion
      OBJECT GET oItem.SMBIOSPresent TO vSMBIOSPresent
      OBJECT GET oItem.SoftwareElementID TO vSoftwareElementID
      OBJECT GET oItem.SoftwareElementState TO vSoftwareElementState
      OBJECT GET oItem.Status TO vStatus
      OBJECT GET oItem.TargetOperatingSystem TO vTargetOperatingSystem
      OBJECT GET oItem.Version TO vVersion
      ' // Release the object
      oItem = NOTHING
   LOOP

   ' // Release the enumerator
   pEnum = NOTHING
   ' // Release the collection
   pObjectSet = NOTHING
   ' // Release the service
   pService = NOTHING

END SUB
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   WMI_Win32_BIOS

END FUNCTION
' ========================================================================================