Enumerating WMI Settings

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Knowing how WMI is configured on a computer can be very useful when you are debugging scripts or troubleshooting problems with the WMI service itself. For example, many WMI scripts are written under the assumption that root\cimv2 is the default namespace on the target computer. As a result, script writers who need to access a class in root\cimv2 often fail to include the namespace in the GetObject moniker, as shown in the following code sample:

Set colServices = GetObject("winmgmts:").ExecQuery _     ("SELECT * FROM Win32_Service") 

If root\cimv2 is not the default namespace on the target computer, this script will fail. To prevent this from happening, the namespace root\cimv2 must be included in the moniker, as shown in the following code sample:

Set colServices = GetObject("winmgmts:root\cimv2").ExecQuery _     ("SELECT * FROM Win32_Service") 

If the default namespace on the target computer is different from the namespace assumed by a script, the script will fail. On top of that, the user will be presented with the somewhat misleading error message "Invalid class." In truth, the failure is not because the class is invalid but because the class cannot be found in the default namespace. This is a difficult problem to troubleshoot, because you are likely to investigate possible problems with the class rather than problems with the namespace that was (or, in this case, was not) specified.

You can use the Win32_WMISetting class to determine how WMI has been configured on a computer. Configuration details such as the default namespace or the WMI build number can be useful in troubleshooting script problems. These settings also provide important administrative information such as how, or even whether, WMI errors are logged on a computer and which WMI providers will automatically be reloaded if you need to rebuild the WMI repository.

Scripting Steps

Listing 8.10 contains a script that enumerates WMI settings on a computer. To carry out this task, the script must perform the following steps:

  1. Create a variable to specify the computer name.
  2. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."
  3. Use the ExecQuery method to query the Win32_WMISetting class.

    This query returns a collection consisting of the WMI configuration settings for the computer.

  4. For each group of WMI settings in the collection, echo the value of the specified property.

    Because the autorecover MOFs are stored in an array, a For Each loop must be used to enumerate each MOF.

Listing 8.10   Enumerating WMI Settings

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colWMISettings = objWMIService.ExecQuery _     ("SELECT * FROM Win32_WMISetting") For Each objWMISetting in colWMISettings     Wscript.Echo "Default namespace: " & _         objWMISetting.ASPScriptDefaultNamespace     Wscript.Echo "Backup interval: " & objWMISetting.BackupInterval     Wscript.Echo "Last backup: " & objWMISetting.BackupLastTime     Wscript.Echo "Build version: " & objWMISetting.BuildVersion     Wscript.Echo "Repository directory: " & _         objWMISetting.DatabaseDirectory     Wscript.Echo "Enable events: " & objWMISetting.EnableEvents     Wscript.Echo "High threshold on client objects: " & _         objWMISetting.HighThresholdOnClientObjects     Wscript.Echo "High threshold on events: " & _         objWMISetting.HighThresholdOnEvents     Wscript.Echo "Installation folder: " & _         objWMISetting.InstallationDirectory     Wscript.Echo "Logging folder: " & objWMISetting.LoggingDirectory     Wscript.Echo "Logging level: " & objWMISetting.LoggingLevel     Wscript.Echo "Low threshold on client objects: " & _         objWMISetting.LowThresholdOnClientObjects     Wscript.Echo "Low threshold on events: " & _         objWMISetting.LowThresholdOnEvents     Wscript.Echo "Maximum log file size: " & objWMISetting.MaxLogFileSize     Wscript.Echo "Maximum wait time on client objects: " & _         objWMISetting.MaxWaitOnClientObjects     Wscript.Echo "Maximum wait time on events: " & _         objWMISetting.MaxWaitOnEvents     Wscript.Echo "MOF Self-install folder: " & _         objWMISetting.MofSelfInstallDirectory     For Each strMOF in objWMISetting.AutorecoverMofs         Wscript.Echo "Autorecover MOF: " & strMOF     Next Next

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

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