Reading String-valued and DWORD-valued Entries

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

The majority of registry values that hold useful information for a system administrator are made up of either alphanumeric characters (REG_SZ) or numbers (REG_DWORD). String values in the registry are often clearly interpretable words, such as the name of a component manufacturer. Registry values of other types, like binary values, cannot be interpreted quite so readily.

You can read REG_SZ and REG_DWORD values by using the GetStringValue and the GetDWORDValue methods, respectively.

Scripting Steps

Listing 16.3 contains a script that retrieves both a string value and a DWORD value from the registry. To carry out this task, the script performs the following steps:

  1. Create constants that hold the hexadecimal numbers corresponding to the HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE registry subtrees.
  2. Create a variable and set it to the name of the computer where the script will run.
  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 value is located.
  5. Create a variable and set it to the name of the entry.
  6. Use the GetDWORDValue method to retrieve the value of the entry. The value is returned in the dwValue variable that is passed to the method. GetDWORDValue is used because the data type of the value of the entry, Console, is REG_DWORD.
  7. Display the value retrieved using the Echo method.
  8. Repeat steps 4 through 7, substituting the GetStringValue method for GetDWORDValue in step 6. You must use the GetStringValue method rather than the GetDWORDValue method to retrieve the value of the second entry, TrustPolicy. This is because the data type of the value is REG_SZ (string).

Listing 16.3   Reading String and DWORD Registry Values

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
Const HKEY_CURRENT_USER = &H80000001 Const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _     strComputer & "\root\default:StdRegProv") strKeyPath = "Console" strEntryName = "HistoryBufferSize" objReg.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strEntryName,dwValue Wscript.Echo "Current History Buffer Size: " & dwValue  strKeyPath = "SOFTWARE\Microsoft\Windows Script Host\Settings" strEntryName = "TrustPolicy" objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue Wscript.Echo "Current WSH Trust Policy Value: " & 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