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

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?
murrycAsked:
Who is Participating?
 
merowingerCommented:
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
 
speshalystCommented:
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
 
guy-pcCommented:
Click Start > Run
Type reg delete HKLM\Software\Microsoft\MSLicensing
that will do it
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.