Deleting a Registry Subkey

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

You can use the DeleteKey method to delete a registry subkey. The script in Listing 16.15 deletes the subkey HKLM\SOFTWARE\System Admin Scripting Guide, added by the script in Listing 16.8. If you have not already run Listing 16.8, you should do so before running the following script. Otherwise, there will be no subkey for this demonstration script to delete.

Scripting Steps

Listing 16.15 contains a script that deletes the HKLM\SOFTWARE\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:

  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 to be deleted.
  5. Use the DeleteKey method to delete the subkey.

Listing 16.15   Deleting a Registry Key

1 2 3 4 5 6 7 8 
Const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _      strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\System Admin Scripting Guide" objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath

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