Deleting Registry Entries

Microsoft® Windows® 2000 Scripting Guide

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:

  1. Create a constant that holds the hexadecimal number corresponding to the HKEY_LOCAL_MACHINE 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 subkey from which the entries will be deleted.
  5. Create variables and set it to the names of the entries being deleted.
  6. 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 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