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

Posted on 2007-07-23
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?
Question by:murryc
    LVL 31

    Accepted Solution

    try the dos command "reg delete"
    which u can execute in vbscript with: "reg delete HKLM\Software\Microsoft\MSLicensing /va /f"

    More informations: reg delete /?
    LVL 16

    Expert Comment

    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


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


    Expert Comment

    Click Start > Run
    Type reg delete HKLM\Software\Microsoft\MSLicensing
    that will do it

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    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…
    Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now