In the second article of this series, I will continue presenting ways of using scripting with Windows Management Instrumentation methods in order to manipulate Windows registry. Note, that these methods require WMI Standard Registry provider, which is installed by default on Windows 2000 and XP platforms.
In his latest article, Marcin Policht presents additional ways of using scripting with Windows Management Instrumentation (WMI) methods in order to manipulate the Windows registry.
The first article contained examples of implementing the following methods:
- GetBinaryValue – reading registry value of BINARY type
- GetDWORDValue – reading registry value of DWORD type
- GetExpandedStringValue – reading registry value of EXPANDED STRING type
- GetMultiStringValue – reading registry value of MULTI STRING type
- GetStringValue – reading registry value of STRING type
I will continue, by providing code samples showing how to take advantage of the remaining methods:
- CreateKey – creates registry key
- SetBinaryValue – writing registry value of BINARY type
- SetDWORDValue – writing registry value of DWORD type
- SetExpandedStringValue – writing registry value of EXPANDED STRING type
- SetMultiStringValue – writing registry value of MULTI STRING type
- SetStringValue – writing registry value of STRING type
- DeleteKey – deleting registry key
- DeleteValue – deleting registry value
- EnumKey – enumerating registry key
- EnumValues – enumerating registry value
As before, the proper execution of the code relies on having available a number of constants:
|
|
To save some space, we will assume that these five constants are defined in every one of our sample scripts (just make sure you copy them at the beginning of each).
CreateKey
The following code will create key named MyCompany in the HKEY_LOCAL_MACHINESOFTWARE area of the registry. The target computer name is stored in the variable sComputer. To use this script, set sComputer, hTree, and sKey variables to appropriate values (to use the local computer, you can set sComputer to a single dot (.)
|
SetBinaryValue
In this example, I create a binary value named BinValue (located in the previously created registry key) and set it to ff 01 01 01. Note that aValue is an array of strings, each representing an integer between 0 and 255 (representing a single byte).
|
SetDWordValue
This time, the code creates a registry entry named DWordValue of type DWORD, located in the same key as in the previous two examples. The entry is set to decimal 11 (or 0x0000000b in hexadecimal). Note that the value is specified as an integer (but you can use any other radix that is recognized by VBScript).
|
SetExpandedStringValue
Expanded string type contains system environment variables. Here is an example of a script creating such entry (using %SystemRoot% environment variable).
|
SetMultiStringValue
Multisting type consists of multiple strings. Note that when viewed in the REGEDT32 on Windows 2000, each string will appear on a separate line. REGEDIT displays them as one continous sting of characters.
|
SetStringValue
This method is the most straightforward and most commonly used.
|
DeleteKey
As the name indicates, this method deletes existing key. Here is the sample code:
|
DeleteValue
As before, the name of the method is self-explanatory and no additional comments are necessary.
|
EnumKey
EnumKey method enumerates all subkeys for the key, which name you specify. This sample script displays each subkey separately. Note, that the results are obtained by listing entries of the array stored in the sNames property (part of output parameter object).
|
EnumValues
This method works similarly to the previous one, but instead of enumerating subkeys of a key, it performs the same for all values contained in it. The output contains also the type of each value. The types are represented as integers. In order to make the output more meaningful, I assigned appropriate name to each value and defined them as constants. The output displays each value and its corresponding data type as a single line.
|
This article was originally published on Aug 13, 2002
1 of
1
Acceptable Use Policy
About Us |
Privacy Notice |
Contact Us |
Advertise |
Sitemap |
California – Do Not Sell My Info
Advertiser Disclosure:
Thanks for your registration, follow us on our social networks to keep up-to-date