Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
Expanded strings are strings that can include variables; these variables are resolved when an application or a service uses the value. For example, the value of an entry that references a file might include the variable %systemroot%. When a service, such as the Event Log, references the entry, the %systemroot% variable is replaced by the name of the directory containing the Windows system files (for example, C:\Windows). On a different computer, one with Windows installed on drive D, this same registry value might be replaced by D:\Windows.
If you need to create an entry that includes a value that might change, such as the path environment variable or the location of the current user s profile, you can use the SetExpandedStringValue method.
Scripting Steps
Listing 16.11 contains a script that creates an expanded string-valued registry entry in the System Admin Scripting Guide subkey created by the script in Listing 16.8. To carry out this task, the script must perform the following steps:
- Create a constant that holds the hexadecimal number corresponding to the HKEY_LOCAL_MACHINE subtree.
- Create a variable and set it to the computer name.
- Use a GetObject call to connect to the WMI namespace root\default, and set the impersonation level to "impersonate."
- Create variables in which to specify the following:
- Subkey in which the entries will be created.
- Name of the expanded string-valued registry entry being created.
- Expanded string value of the registry entry being created.
- Use the SetExpandedStringValue method to create the new entry with the expanded string value.
Listing 16.11 Creating Expanded String-valued Entries
1 2 3 4 5 6 7 8 9 10 11 12
| Const HKEY_LOCAL_MACHINE = &H80000002 strComputer = ". " Set objReg=GetObject( "winmgmts:{impersonationLevel=impersonate}!\\ " & _ strComputer & "\root\default:StdRegProv ") strKeyPath = "SOFTWARE\System Admin Scripting Guide " strValueName = "Expanded String Value Name " strValue = "%PATHEXT% " objReg.SetExpandedStringValue _ HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue |
Send us your feedback | « Previous | Next » |