1.3 WMI providers discovery


1.3 WMI providers discovery

Some of you may wonder why we need to discover the WMI provider existence with their classes when they are documented in the WMI SDK. First, not all providers available from WMI are documented in the WMI SDK, which implies that not all available WMI classes are documented. Mastering a discovery technique will allow you to understand how the CIM repository defines the existence of its providers and which class they support. The discovery will help to acquire knowledge about the WMI provider capabilities and get a better understanding about what it is possible to do when using their classes. This is why it is useful to have a WMI provider discovery technique. Moreover, if tomorrow a new application registers some new providers and adds new classes in the CIM repository, mastering the discovery technique immediately gives you the required information to develop an application or a script that leverages these new classes, even if they are not documented by the application developer (i.e., because the classes are intended for the application's internal use only).

As we have seen in the previous section, we know that every WMI provider registered in the CIM repository creates some instances from a set of system classes and that the set of system classes used depends on the WMI provider type. Sample 4.30 in the appendix shows how a script can browse the CIM repository to locate WMI instances across the namespaces. If we reuse that piece of code to locate the instances of the __Win32Provider system class used to register WMI providers across all existing namespaces, we will locate all registered WMI providers in the CIM repository. To be complete and determine the WMI provider type (Instance provider, Method provider, etc.), we must also check if each __Win32Provider instance has some associated references.

Listing the WMI providers with their types is only a piece of the desired information, because we want to know what classes are supported by the providers. This information is available in the class definition itself. The WMI provider that a class relates to depends on the provider type:

  • For the class providers, the Instance providers, the Method providers, and the Property providers, the provider qualifier is set in the class definition, which determines the provider supporting the class (see Figure 1.8).

    click to expand
    Figure 1.8: The provider qualifier of a class to determine the supported WMI provider.

  • For the event providers, the __EventProviderRegistration system class exposes a property called EventQueryList. This property contains a collection of the WQL queries supported by the event provider. In these WQL queries, the various classes supported by the event provider are mentioned (see Figure 1.9). These classes are categorized as intrinsic and extrinsic event classes.

    click to expand
    Figure 1.9: The EventQueryList property of one __EventProviderRegistration instance.

  • For the event consumer providers, the __EventConsumerProviderRegistration system class exposes a property called ConsumerClassNames. This property contains a collection of classes supported by the event consumer provider (see Figure 1.10).

    click to expand
    Figure 1.10: The ConsumerClassNames property of one __EventConsumerProviderRegistration.

In Understanding WMI Scripting, Chapter 4, we saw how to retrieve the qualifiers of a class and enumerate a collection of properties. We can reuse this knowledge to develop script logic that retrieves the registered providers with the classes they provide. This logic is implemented in Samples 1.1 through 1.3.

Sample 1.1 contains the first part of the script. This part uses a structure that we have already seen many times in the first book, Understanding WMI Scripting. Lines 13 through 17 contain the parameter definitions that can be used from the command line. Next, the script processes the command-line parameters analysis (lines 39 through 48).

Sample 1.1: Locating WMI provider registration instances with their supported classes (Part I)

start example

  1:<?xml version="1.0"?>  .:  8:<package>  9: <job> ..: 13:  <runtime> 14:    <named name="Machine" helpstring="determine the WMI system to connect to.                  (default=LocalHost)" required="false" type="string"/> 15:    <named name="User" helpstring="determine the UserID to perform the remote connection.                  (default=none)" required="false" type="string"/> 16:    <named name="Password" helpstring="determine the password to perform the remote connection.                  (default=none)" required="false" type="string"/> 17:  </runtime> 18: 19:  <script language="VBScript" src="/books/2/679/1/html/2/.\Functions\DisplayInstanceProperties.vbs" /> 20:  <script language="VBScript" src="/books/2/679/1/html/2/.\Functions\TinyErrorHandler.vbs" /> 21: 22:  <object prog  reference="true"/> 23:  <object prog  /> 24: 25:  <script language="VBscript"> 26:  <![CDATA[ ..: 30:  Const cComputerName = "LocalHost" 31:  Const cWMINameSpace = "Root" 32:  Const cWMINamespaceclass = "__NAMESPACE" 33:  Const cWMIclass = "_Win32provider" ..: 39:  '-------------------------------------------------------------------------------- 40:  ' Parse the command line parameters 41:  strUserID = WScript.Arguments.Named("User") 42:  If Len(strUserID) - 0 Then strUserID = "" 43: 44:  strPassword = WScript.Arguments.Named("Password") 45:  If Len(strPassword) = 0 Then strPassword = "" 46: 47:  strComputerName = WScript.Arguments.Named("Machine") 48:  If Len(strComputerName) = 0 Then strComputerName = cComputerName 49: 50:  DisplayNameSpaces cWMINameSpace, cWMIclass, strUserID, strPassword, strComputerName 51: ..: ..: ..: 

end example

Once the command-line parameters analysis completes, the script calls the DisplayNameSpaces() function (line 50). Note that the parameters passed to the function are the Root namespace (defined in line 31) and the __Win32Provider system class (defined in line 33). The DisplayNameSpaces() function uses the same parameters as Sample 4.30 (see the appendix) to browse the namespaces defined in the CIM repository. Although the function is still using a recursive model, the internal logic has been slightly modified to suit our needs. Sample 1.2 shows the updated version of this function.

Sample 1.2: Locating WMI Provider registration instances with their supported classes (Part II)

start example

  ..:  ..:  ..:  51:  52:  ' ----------------------------------------------------------------------  53:  Private Function DisplayNameSpaces (ByVal strWMINameSpace, _  54:                                      ByVal strWMIclass, _  55:                                      ByVal strUserID, _  56:                                      ByVal strPassword, _  57:                                      ByVal strComputerName)  ..:  66:    objWMILocator.Security_.AuthenticationLevel = wbemAuthenticationLevelDefault  67:    objWMlLocator.Security_.ImpersonationLevel = wbemImpersonationLevelImpersonate  68:    Set objWMIServices = objWMILocator.ConnectServer(strComputerName, _  69:                              strWMINamespace, _  70:                              strUserID, _  71:                              strPassword)  72:    If Err.Number Then ErrorHandler (Err)  73:  74:    Set objWMIInstances = objWMIServices.ExecQuery ("Select * From " & strWMIclass)  75:    If Err.Number Then  76:       Err.Clear  77:    Else  78:       WScript.Echo strWMINameSpace  79:       For Each objWMIInstance in objWMIInstances  80:  81:         WScript.Echo "  " & String (40, "-")  82:         WScript.Echo objWMIInstance.Name  83:  84:         For Each objWMIReference in objWMIInstance.References_  85:           WScript.Echo objWMIReference.Path_.class  86:           Select Case LCase (objWMIReference.Path_.class)  87:               Case "_eventproviderregistration"  88:                 DisplaySupportedQueryclasses (objWMlReference.EventQueryList)  89:               Case "—eventconsumerproviderregistration"  90:                 DisplaySupportedConsumerclasses (objWMIReference.ConsumerclassNames)  91:           End Select  92:         Next  93:  94:         Displayproviderclasses objWMIServices, "", objWMIInstance.Name  95:       Next  96:       Set objWMIInstances = Nothing  97:    End If  98:  99:    Set objWMINSInstances - objWMIServices.InstancesOf (cWMINamespaceclass, _ 100:                                wbemQueryFlagShallow) 101:    For Each objWMINS Instance in objWMINSInstances 102:        DisplayNameSpaces strWMINameSpace & "/" & objWMINSInstance.Name, _ 103:                  strWMIclass, strUserID, strPassword, strComputerName 104:    Next ...: 109: End Function 110: ..: ..: ..: 

end example

Once the DisplayNameSpaces() function is called, the code starts by establishing the WMI connection to the examined namespace (lines 66 through 72). Next, the script retrieves all instances of the WMI providers registered in the examined namespace (line 74). For this, it uses the __Win32Provider system class passed as a parameter of the DisplayNameSpaces() function (line 50). If no fault occurs, the code enumerates the retrieved collection (lines 79 through 95). The slight change concerns the logic encapsulated in this particular loop. Originally, the DisplayNameSpaces() function displayed the properties of the retrieved instances. Now, it shows the name of the WMI provider instance (line 82) and retrieves the references of the provider instance by using the References_ property (line 84).

If the references point to an __EventProviderRegistration or an EventConsumerProviderRegistration system class, the script locates the supported classes, as previously explained. For this, it calls the DisplaySupportedQueryClasses() (line 87) or DisplaySupportedConsumerClasses() (line 89) functions based on the system class type used by the reference (lines 85 through 91). These two functions simply enumerate the properties content visible in Figures 1.9 and 1.10.

For each reference found, the script shows the class reference (line 85). For instance, if the WMI provider is an instance provider and a method provider, it shows the __InstanceProviderRegistration and the __MethodProviderRegistration system classes, as shown in the following sample output (lines 9 and 10).

    1: C:\>Locateproviders.Wsf    2: Microsoft (R) Windows Script Host Version 5.6    3: Copyright (C) Microsoft Corporation 1996-2000. All rights reserved.    4:    5: Root    6: Root/CIMV2    7: ----------------------------------------    8: CIMWin32    9: __MethodproviderRegistration   10: __InstanceproviderRegistration   11: > CIM_LogicalFile   12: > CIM_DataFile   13: > Win32_CodecFile   14: > Win32_ShortcutFile   15: > Win32_PageFile   16: > Win32_Directory   17: > Win32_ComputerSystem   18: > Win32_DeviceMemoryAddress   19: > Win32_PortResource   20: > Win32_DMAChannel   21: > Win32_IRQResource   22: > Win32_Environment   23: > Win32_LogicalDisk   ..:   ..:   ..: 

At line 8 of the output, we see the name of the provider. This name is referenced by the provider qualifier of the classes supported by the examined WMI provider (shown in Figure 1.8 for the Win32_Service class). This element can be used to determine the classes that relate to a WMI provider (lines 11 through 23 and more). This is why, at line 94 of Sample 1.2, the script calls the DisplayProviderClasses() function (see Sample 1.3 for the function code). The function call passes the following parameters:

  • The SWBemServices object created when establishing the connection to the examined WMI namespace

  • The provider name (i.e., CIMWin32)

  • An empty class name

Sample 1.3: Locating WMI provider registration instances with their supported classes (Part III)

start example

 ...: ...: ...: 110: 111:  ' ---------------------------------------------------------------------- 112:  Private Function Displayproviderclasses (ByVal objWMIServices, _ 113:                                           ByVal strWMIclass, _ 114:                                           ByVal strproviderName) ...: 121:      Set objWMIInstances = objWMIServices.SubclassesOf (strWMIclass, wbemQueryFlagDeep) 122: 123:      For Each objWMIInstance in objWMIInstances 124:          strProvqualifier = objWMIInstance.qualifiers_.item("provider") 125:          If Not Err.Number Then 126:             If Ucase (strproviderName) = Ucase (strProvqualifier) Then 127:                WScript.Echo "> " & objWMIInstance.Path_.RelPath 128:             End If 129:          End If 130:          strProvqualifier = "" 131:      Next 132: 133:      Set objWMIInstances = Nothing 134: 135:  End Function 136: 137:  ' —------------------------------------------------------------------------------------ 138:  Private Function DisplaySupportedQueryclasses (ByVal arrayEventQueryList) ..: 144:      For Each strEventQuery in arrayEventQueryList 145:          WScript.Echo "> " & Mid (strEventQuery, _ 146:                                   InStrRev (strEventQuery, " ", -1, vbTextCompare) + 1) 147:      Next 148: 149:  End Function 150: 151:  ' -------------------------------------------------------------------------------------- 152:  Private Function DisplaySupportedConsumerclasses (ByVal arrayConsumerclassList) ..: 158:    For Each strConsumerclass in arrayConsumerclassList 159:      WScript.Echo "> " & strConsumerclass 160:    Next 161: 162:  End Function 163: 164:  ]]> 165:  </script> 166: </job> 167:</package> 

end example

The empty class name refers to the root class of the examined namespace. Sample 1.3 contains the code that searches the classes supported by the examined WMI provider from the top class hierarchy.

In the DisplayProviderClasses() function, the code uses the SubClassesOf method of the SWBemServices object with the wbemQueryFlagDeep flag (line 121). This means that the script code retrieves all classes available in the namespace. Don't forget that we use a blank class (line 94) to force a search from the Root of the namespace. Next, the retrieved collection of classes is examined one by one in the For Each loop (lines 123 through 131). For each examined class in the collection, the function retrieves the provider qualifier (line 124) and compares its content (line 126) with the name of the provider passed during the function call (line 114). If there is a match, it means that the examined provider supports the class. In this case, the class name is displayed (line 127). The output is as follows:

   ..:   ..:   ..:   11:> CIM_LogicalFile   12:> CIM_DataFile   13:> Win32_CodecFile   14:> Win32_ShortcutFile   15:> Win32_PageFile   16:> Win32_Directory   17:> Win32_ComputerSystem   18:> Win32_DeviceMemoryAddress   19:> Win32_PortResource   20:> Win32_DMAChannel   21:> Win32_IRQResource   22:> Win32_Environment   23:> Win32_LogicalDisk   ..:   ..:   ..: 

However, because we use the provider qualifier, only the classes representing instances are located. This means that abstract classes, which are often used as parent templates to create subclasses, are not located. In practice, this has no impact on the information we are looking for, because abstract classes do not represent real-world manageable entities (or instances). Since we need to gather information about the classes that represent the real-world entities that we want managed, the abstract classes are useless for our purpose—even if it is good to know their existence in order to have a good knowledge of the implemented object model.

With this script, it is possible to locate all WMI registered providers across all existing namespaces in the CIM repository and find their supported classes. Doing so, the script self-documents the WMI providers available with their characteristics. If, in the future, some applications are adding new providers, a simple run of the script will provide the updated content of the CIM repository with their providers and supported classes.

Next, to gather more information about the classes, a simple run of the LoadCIMinXL.wsf script (see Sample 4.32 in the appendix) provides all the class details with its properties and methods.

The result of the script execution (Samples 1.1 through 1.3) under Windows Server 2003 is summarized in Table 1.1. This table shows the most important WMI providers registered in the CIM repository with their respective namespaces and their type (class provider, instance provider, property provider, etc.).

Table 1.1: The Most Important WMI Providers under the Windows Platforms with Their Capabilities

Provider Name

Provider Classes

Class Provider

Instance Provider

Method Provider

Property Provider

Event Provider

Event Consumer Provider

Support Get

Support Put

Support Enumeration

Support Delete

Windows Server 2003

Windows XP

Windows 2000 Server

Windows 2000 Professional

Windows NT 4.0

ActiveScriptEventConsumer (Optional)

Root/subscription

X

X

X

X

CommandLineEventConsumer (Optional)

Root/subscription

X

X

X

X

EventViewerConsumer (Optional with the WMI Tools)

Root/CIMV2

X

X

X

X

X

LogFileEventConsumer (Optional)

Root/subscription

X

X

X

X

Microsoft WMI Forwarding Consumer Provider

Root/subscription

X

X

Microsoft WMI Forwarding Consumer Trace Event Provider

Root/subscription

X

X

Microsoft WMI Forwarding Event Provider

Root/CIMV2

X

X

NTEventLogEventConsumer

Root/subscription

X

X

X

X

SMTPEventConsumer (Optional)

Root/subscription

X

X

X

X

CIMWin32

Root/CIMV2

X

X

X

X

X

X

X

X

X

X

X

CIMWin32A

Root/CIMV2

X

X

X

X

X

X

X

X

Cluster Event Provider

Root/MSCluster

X

X

MS_CLUSTER_CLASS_PROVIDER

Root/MSCluster

X

X

X

X

MS_CLUSTER_PROVIDER

Root/MSCluster

X

X

X

X

X

X

X

DFSProvider

Root/CIMV2

X

X

X

X

X

X

X

DskQuotaProvider

Root/CIMV2

X

X

X

X

X

X

X

HiPerfCooker_v1

Root/WMI

X

X

X

X

X

HiPerfCooker_v1

Root/CIMV2

X

X

X

X

X

ieinfo5

Root/CIMV2/Applications/MicrosoftIE

X

X

X

X

X

X

IIS__PROVIDER

Root/MicrosoftIISv2

X

X

X

X

X

X

X

X

Microsoft|DSLDAPClassAssociationsProvider|V1.0

Root/directory/LDAP

X

X

X

X

X

X

X

Microsoft|DSLDAPClassProvider|V1.0

Root/directory/LDAP

X

X

X

X

X

X

X

Microsoft|DSLDAPInstanceProvider|V1.0

Root/directory/LDAP

X

X

X

X

X

X

X

X

X

Microsoft|NIB_Provider|V1.0

Root/MicrosoftNLB

X

X

X

X

X

X

X

X

NlbsNicProv

Root/MicrosoftNLB

X

X

X

X

X

X

MS_NT_DNS_PROVIDER

Root/MicrosoftDNS

X

X

X

X

X

X

X

X

MS_NT_EVENTLOG_EVENT_PROVIDER

Root/CIMV2

X

X

X

X

X

X

MS_NT_EVENTLOG_PROVIDER

Root/CIMV2

X

X

X

X

X

X

X

X

X

X

MS_Power_Managemert_Event_Provider

Root/CIMV2

X

X

X

X

X

X

MS_Shutdown_Event_Provider

Root/CIMV2

X

X

X

MS_SNMP_CLASS_PROVIDER (Optional)

Root/snmp/localhost

X

X

X

X

X

X

X

MS_SNMP_ENCAPSULATED_EVENT_PROVIDER (Optional)

Root/snmp/localhost

X

X

X

X

X

MS_SNMP_INSTANCE_PROVIDER (Optional)

Root/snmp/localhost

X

X

X

X

X

X

X

X

X

MS_SNMP_REFERENT_EVENT_PROVIDER (Optional)

Root/snmp/localhost

X

X

X

X

X

MS_VIEW_INSTANCE_PROVIDER

Root/MicrosofIISv2

X

X

X

X

X

X

X

X

MSIProv

Root/CIMV2

X

X

X

X

X

X

X

X

X

X

X

MSVDS_PROVIDER

Root/CIMV2

X

X

X

X

X

X

X

MSVSS_PROVIDER

Root/CIMV2

X

X

X

X

X

X

X

NamedJobObjectActglnfoProv

Root/CIMV2

X

X

X

X

X

X

X

NamedJobObiectlLimitSettingProv

Root/CIMV2

X

X

X

X

X

X

X

NamedJobObjectProv

Root/CIMV2

X

X

X

X

X

X

X

NamedJobObjectSecLimitSettingProv

Root/CIMV2

X

X

X

X

X

X

X

NetDiagProv

Root/CIMV2

X

X

X

X

X

X

X

NetFrameworkv1Provider

Root/NetFrameworkv1

X

X

X

X

X

X

X

NT5_GenericPerfProvider_V1

Root/CIMV2

X

X

X

X

X

X

X

PolicSOM

Root/Policy

X

X

X

X

X

X

X

PolicStatus

Root/Policy

X

X

X

X

RegistryEventProvider

Root/DEFAULT

X

X

X

X

X

X

RegPropProv

Root/DEFAULT

X

X

X

X

X

X

X

X

RegProv

Root/DEFAULT

X

X

X

X

X

X

X

X

X

X

RegProv

Root/CIMV2

X

X

X

X

X

ReplProv1

Root/MicrosoftActiveDirectory

X

X

X

X

X

RouteEventProvider

Root/CIMV2

X

X

X

RouteProvider

Root/CIMV2

X

X

X

X

X

X

X

Rsop Logging Mode Provider

Root/RSOP

X

X

X

Rsop Planning Mode Provider

Root/RSOP

X

X

X

SECRCW32

Root/CIMV2

X

X

X

X

X

X

X

X

X

X

X

SessionProvider

Root/CIMV2

X

X

X

X

X

X

X

X

SystemRestoreProv

Root/Default

X

X

X

X

X

X

TrustPrv

Root/MicrosoftActiveDirectory

X

X

X

X

VolumeChangeEvents

Root/CIMV2

X

X

X

WBEMCORE

Root/CIMV2

X

X

X

X

X

X

X

X

X

Win32_WIN32_COMPUTERSYSTEMWINDOWSPRODUCTACTIVATIONSETTING_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_WINDOWSPRODUCTACTIVATION_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_PROXY_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TERMINAL_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TERMINALSERVICE_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TERMINALSERVICESETTING_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TERMINALSERVICETOSETTING_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TERNINALTLRNINALSETTING rov

Root/CIMV2

X

X

X

X

X

X

X

Win32_WIN32_TSACCOUNT_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TSCLIENTSETTING_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TSENVIRONMENTSETTING_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TSGENERALSETTING_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32 TSLOGONSETTING_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TSNEFWORKADAPTERLTSTSETTING_Prov

Root/CIMCV2

X

X

X

X

X

X

X

X

Win32_WIN32_TSNETWORKADAPTERSETTING_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TSPERMISSIONSSETTING_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TSREMOTECONTROLSETTING_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TSSESSIONDIRECTORY_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TSSESSIONDIRECTORYSETTING_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32_WIN32_TSSESSIONSETTING_Prov

Root/CIMV2

X

X

X

X

X

X

X

X

Win32ClockProvider

Root/CIMV2

X

X

X

WMIEventProv

Root/WMI

X

X

X

X

WMIEventProv

Root/MicrosoftNLB

X

X

WMIPingProvider

Root/CIMV2

X

X

X

X

X

WMIProv

Root/WMI

X

X

X

X

X

X

X

X

X

X

WMIProv

Root/MicrpsoftNLB

X

X

X

X

X

X

X

Microsoft WMI Updating Consumer Assoc Provider

Root/subscription

X

X

X

X

X

X

Microsoft WMI Updating Consumer Event Provider

Root/subscription

X

X

Microsoft WMI Updating Consumer Provider

Root/subscription

X

X

Microsoft WMI Template Association Provider

Root/subscription

X

X

X

X

Microsoft WMI Template Event Provider

Root/subscription

X

X

Microsoft WMI Template Provider

Root/subscription

X

X

X

X

X

X

Microsoft WMI Transient Event Provider

Root/subscription

X

X

Microsoft WMI Transient Provider

Root/subscription

X

X

X

X

X

X

Microsoft WMI Transient Reboot Event Provider

Root/subscription

X

X




Leveraging WMI Scripting
Leveraging WMI Scripting: Using Windows Management Instrumentation to Solve Windows Management Problems (HP Technologies)
ISBN: 1555582990
EAN: 2147483647
Year: 2003
Pages: 82
Authors: Alain Lissoir

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net