Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
The DeleteValue method deletes a registry entry. (If you are wondering why the name is DeleteValue rather than DeleteEntry, it is because a number of different terms are used to refer to registry entries, including values). The script in Listing 16.14 deletes all registry entries added by the scripts in the "Creating Registry Subkeys and Entries" section of this chapter. Run those scripts before running this one otherwise, there will be no entry for this demonstration script to delete.
Scripting Steps
Listing 16.14 contains a script that deletes entries from the registry. 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 a variable and set it to the subkey from which the entries will be deleted.
- Create variables and set it to the names of the entries being deleted.
- Use the DeleteValue method to delete the various registry entries.
Listing 16.14 Deleting Registry Entries
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| Const HKEY_LOCAL_MACHINE = &H80000002 strComputer = ". " Set objReg=GetObject( "winmgmts:{impersonationLevel=impersonate}!\\ " & _ strComputer & "\root\default:StdRegProv ") strKeyPath = "SOFTWARE\System Admin Scripting Guide " strDWORDValueName = "DWORD Value Name " strExpandedStringValueName = "Expanded String Value Name " strMultiStringValueName = "Multi String Value Name " strStringValueName = "String Value Name " objReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strDWORDValueName objReg.DeleteValue _ HKEY_LOCAL_MACHINE,strKeyPath,strExpandedStringValueName objReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strMultiStringValueName objReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strStringValueName |
Send us your feedback | « Previous | Next » |