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:
I will continue, by providing code samples showing how to take advantage of the remaining methods:
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
Acceptable Use Policy
Advertiser Disclosure:
Thanks for your registration, follow us on our social networks to keep up-to-date
Marcin Policht obtained his Master of Computer Science degree about 20 years ago and has been since then working in the Information Technology field, handling variety of responsibilities, but focusing primarily on the areas of identity and access management, virtualization, system management, and, more recently private, hybrid, and public cloud services. He has authored the first book dedicated to Windows Management Instrumentation and co-written several others dealing with subjects ranging from core operating system features to high-availability solutions. His articles have been published on such Web sites as ServerWatch.com and DatabaseJournal.com. For his contributions to the Microsoft technical community, he has been awarded the title of Microsoft MVP over the last ten years.
Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved
Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.