Writing Resource Properties

Microsoft® Windows® 2000 Scripting Guide

In Windows 2000, WMI is primarily a read-only technology; you use it mainly to retrieve information about managed resources. However, some WMI properties are read/write. This means you can use a script not only to retrieve the values of these properties but also to configure those values.

For example, the script in Listing 6.25 retrieves all instances of the Win32_OSRecoveryConfiguration class. (In this case, the class contains only a single instance.) The script provides new values for properties such as DebugInfoType and DebugFilePath and then applies the changes (and thus configures operating system recovery options) by using the Put_ method. If you do not call the Put_ method, the changes will not be applied.

Note

  • This template works only for properties that are writable. Attempting to change a read-only property will result in an error.

Listing 6.25 Template for Writing Resource Properties

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
strComputer = "."
strClassName = "Win32_OSRecoveryConfiguration"
strNamespace = "\root\cimv2"
Set objSWbemServices = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & strNamespace)
Set colInstances = objSWbemServices.ExecQuery _
 ("SELECT * FROM " & strClassName)
For Each objInstance in colInstances
 objInstance.DebugInfoType = 1
 objInstance.DebugFilePath = "c:\scripts\memory.dmp"
 objInstance.OverWriteExistingDebugFile = False
 objInstance.Put_
Next

To use this template with other WMI classes and to configure other WMI properties:

  1. Set the value of strClassName to the name of the WMI class.

  2. If necessary, set the value of strNamespace to the appropriate WMI namespace.

  3. Replace the statements within the For Each loop that configure new property values. Remove the following lines, and replace them with the appropriate lines of code for the properties being modified:

    objInstance.DebugInfoType = 1
    objInstance.DebugFilePath = "c:\scripts\memory.dmp"
    objInstance.DebugInfoType = 1
    objInstance.DebugFilePath = "c:\scripts\memory.dmp"
    objInstance.OverWriteExistingDebugFile = False