Previous Page
Next Page

Unleashing the Power of the StdRegProv Class

The importance of the StdRegProv class is the power it brings to a script. In Chapter 1, "Starting from Scratch," our tutorial script illustrated using RegRead. You could follow the same methodology and use the RegWrite and RegDelete methods of WshShell, but there are limitations to using WshShell to work with the registry: You cannot work remotely, and there is no enumeration. However, all problems are resolved by using StdRegProv. It has 16 methods defined. These methods and a description of what they can do are listed in Table 17-2.

Table 17-2. StdRegProv Methods

Method

Description

CheckAccess

Verifies that the user has the specified access permissions

CreateKey

Creates a subkey

DeleteKey

Deletes a subkey

DeleteValue

Deletes a named value

EnumKey

Enumerates one or more subkeys

EnumValues

Enumerates the named values of a key

GetBinaryValue

Gets the binary data value of a named value

GetDWORDValue

Gets the DWORD data value of a named value

GetExpandedStringValue

Gets the expanded string data value of a named value

GetMultiStringValue

Gets the multiple string data values of a named value

GetStringValue

Gets the string data value of a named value

SetBinaryValue

Sets the binary data value of a named value

SetDWORDValue

Sets the DWORD data value of a named value

SetExpandedStringValue

Sets the expanded string data value of a named value

SetMultiStringValue

Sets the multiple string values of a named value

SetStringValue

Sets the string value of a named value


One useful task you can perform as a network administrator is to create a key in the registry that you use to keep track of certain machines. This is similar to a trick I used to use with the Microsoft Systems Management Server product, where I placed a certain text file in the root drive of the workstation and used the presence of the file in creating ad hoc Systems Management Server (SMS) collections.

Just the Steps

To create a registry key

1.
Create a constant for HKLM and assign it the value of &H80000002.

2.
Define variables to hold the registry path you want to create.

3.
Use GetObject to create an instance of the WMI StdRegProvider class.

4.
Use the CreateKey method and feed it the HKLM constant and the registry path variable defined earlier.



Previous Page
Next Page