9.2. Setting a Value

Problem

You want to create, modify, or delete a registry value.

Solution

Using a graphical user interface

  1. Open the Registry Editor (regedit.exe).

  2. Browse to the parent key of the value you want to set or delete.

  3. To create a value:

  4. Right-click on the parent key and select New and the type of value you want to create.

  5. Type the name of the value and hit enter twice. This should cause the Edit dialog box to open.

  6. Type the value for the value and click OK.

  7. To modify a value:

    1. In the right pane, right-click on the value and select Modify.

    2. Enter the new data for the value and click OK.

  8. To delete a value:

    1. In the right pane, right-click on the value and select Delete.

    2. Click Yes to confirm.

Using a command-line interface

The following command sets a registry value:

> reg add \\<ServerName>\<Key> /v <ValueName> /t <ValueType> /d <ValueData>

For example:

> reg add \\fs01\HKLM\Software\Rallencorp /v Version /t REG_SZ /d "1.2"
> reg add \\.\HKLM\Software\Rallencorp /v Setting1 /t REG_DWORD /d 1024

One nice thing about the reg add command is that it automatically creates the Rallencorp subkey if it doesn't already exist.

This command deletes a registry value:

> reg delete \\<ServerName>\<Key> /v <ValueName>

For example:

> reg delete \\fs01\HKLM\Software\Rallencorp /v Version

Using VBScript

Tip

WMI has different methods for setting each of the registry value datatypes. For example, to set a DWORD, you must use SetDWORDValue, not SetStringValue. See Table 9-1 for the complete list of methods.

' This code ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.