Changing String-valued and DWORD-valued Entries

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Changing the values of registry entries is a common registry management task. The most challenging aspect of that task is determining which entries you need to change, and to which values they must be changed. After you have this information, you must choose the appropriate Registry Provider methods for making the change.

To change a string value (REG_SZ), you use the SetStringValue method; to change a numeric value (DWORD), you use the SetDWORDValue method. Each of these methods takes four parameters:

  • A constant that specifies the subtree in which the value being changed is located.
  • The path to the subkey in which the value is located.
  • The name of the entry with the value to be changed.
  • The new value.

These parameters are similar to the parameters used to read registry entries. The only difference is that when registry entries are read, the fourth parameter represents the value read from the registry; when registry entries are configured, the fourth parameter represents the new value being written to the registry.

Be certain to investigate whether other methods of configuration are available before deciding to script direct changes to the registry.

Caution

  • Regardless of where you obtain your information, always back up the registry before modifying it in any way.

Scripting Steps

Listing 16.7 contains a script that changes the values of both a DWORD and a String value in the registry. To carry out this task, the script must perform the following steps:

  1. Create a constant that holds the hexadecimal number corresponding to the HKEY_LOCAL_MACHINE registry subtree.
  2. Create a variable and set it to the computer name.
  3. Use a GetObject call to connect to the WMI namespace root\default, and set the impersonation level to "impersonate."
  4. Create a variable and set it to the path of the registry subkey in which the entry is located.
  5. Create a variable and set it to the name of the entry.
  6. Use the SetDWORDValue method to set the value of the HistoryBufferSize registry entry to the value stored in the dwValue variable (300).
  7. Set the values of the variables holding the entry name and value to use in setting the string-valued entry.
  8. Use the SetStringValue method to set the value of the FaceName registry entry to the value (Lucida Console) stored in the strValue variable.

Listing 16.7   Changing Registry String and DWORD Values

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 
Const HKEY_CURRENT_USER = &H80000001 strComputer = "." Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _     strComputer & "\root\default:StdRegProv") strKeyPath = "Console" strEntryName = "HistoryBufferSize" dwValue = 300 objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strEntryName, dwValue strEntryName = "FaceName" strValue = "Lucida Console" objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, _     strEntryName, strValue

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net