?
Solved

Script or batch to delete registry key and subkeys within it.

Posted on 2007-07-23
3
Medium Priority
?
12,261 Views
Last Modified: 2011-12-15
How do you vbs or batch command to delete a registy key that has keys below it.  I need to delete the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSLicensing but it might have 2-3 keys below it that need to be deleted with it.  I have tried using the VBS script...

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.RegDelete "HKLM\Software\Microsoft\MSLicensing\"
Set WshShell = Nothing

But it throws any error becuase I have to tell it to delete each subkey first.  The keys might be different for each computer, so cannot script to delete the subkeys.  How do I script or batch to delete the entire key with subkeys?
0
Comment
Question by:murryc
3 Comments
 
LVL 31

Accepted Solution

by:
merowinger earned 2000 total points
ID: 19551207
try the dos command "reg delete"
which u can execute in vbscript with:
WshShell.run "reg delete HKLM\Software\Microsoft\MSLicensing /va /f"

More informations: reg delete /?
0
 
LVL 16

Expert Comment

by:speshalyst
ID: 19551312
Its pretty neat on the COmmand LIne...

REG DELETE KeyName [/v ValueName | /ve | /va] [/f]

  KeyName    [\\Machine\]FullKey
    Machine  Name of remote machine - omitting defaults to the current machine
             Only HKLM and HKU are available on remote machines
    FullKey  ROOTKEY\SubKey
    ROOTKEY  [ HKLM | HKCU | HKCR | HKU | HKCC ]
    SubKey   The full name of a registry key under the selected ROOTKEY
  ValueName  The value name, under the selected Key, to delete
             When omitted, all subkeys and values under the Key are deleted
  /ve        delete the value of empty value name <no name>
  /va        delete all values under this key
  /f         Forces the deletion without propmt

Examples:

  REG DELETE HKLM\Software\MyCo\MyApp\Timeout
    Deletes the registry key Timeout and its all subkeys and values

 
0
 

Expert Comment

by:guy-pc
ID: 19553287
Click Start > Run
Type reg delete HKLM\Software\Microsoft\MSLicensing
that will do it
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Issue: Unstable cursor in Windows XP and Windows runs extremely slow in that any click will bring up the Hour glass (sometimes for several seconds before giving you what you want) . Troubleshooting Process and the FINAL FIX: This issue see…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question