win2k domain - delete registry key upon login

Posted on 2005-05-02
Last Modified: 2008-01-09

i want to delete a HKEY Current USer registry value with a login script, can anyone provide the syntax please?

Question by:acetate
    LVL 9

    Expert Comment

    Here is what I do :

    1. Download
    Extract file regdelw.exe from it, and put it under %windir% (Windows directory).
    2. In the startup folder (%userprofile%\Start Menu\Programs\Startup), create a text file and put this line into the file :
    regdelw "give_here_the_key_to_be_deleted" /q /n
    3. Save this file with any name, and extension of either .bat or .cmd
    LVL 7

    Assisted Solution

    As paraqhs points out, there are numerous ways to accomplish this task.  One of the easiest, in my opinion, is using the RegDelete method of the WScript.Shell object in VBScript.  The following 5 lines of code will work with nothing more than the WSH (no external requirements):

    Set objWSHShell = WScript.CreateObject("WScript.Shell")
    objWSHShell.RegWrite "HKCU\Software\Microsoft\Testing", 1, "REG_SZ"
    MsgBox "Please confirm that the HKCU\Software\Microsoft\Testing value was created properly.", vbInformation, "Waiting to remove registry entry"
    objWSHShell.RegDelete "HKCU\Software\Microsoft\Testing"
    MsgBox  "Please confirm that the HKCU\Software\Microsoft\Testing value was deleted properly.", vbInformation, "Completed removing registry entry"

    This actually creates a dummy value (using RegWrite), MsgBox's to pause execution and allow you to confirm it was created successfully, then removes this value and MsgBox's again.  In your scenario, you would only need two lines (similar to below, but with updated registry path, of course):

    Set objWSHShell = WScript.CreateObject("WScript.Shell")
    objWSHShell.RegDelete "HKCU\Software\Microsoft\Testing"

    Save this file with a .vbs extension, and you can use it in your logon script.  Good luck!
    LVL 13

    Expert Comment

    I'm assuming you already know how to merge a reg file via login script. Here is the syntax to remove keys and values using a reg file.

    Of course you know that to add a new value and data, you structure the file like this:



    If you want to delete a value, create a reg file with the value you're after and add a minus sign after the equals. In other words, replace the value data with a minus sign, like this:



    If on the other hand you want ot delete a entire key, add a minus sign before the key name [but inside the brackets] like this:



    Of course, if all you want to do is remove the data but not the key or the value, it would be:


    LVL 13

    Expert Comment

    Oops! this is a Windows 2000 question! The proper header for the file should be:

         Windows Registry Editor Version 5.00

    instead of


    (although both will work)

    And also sorry for the spelling and grammar errors...
    LVL 13

    Accepted Solution

    One more thing (I feel like Lt. Columbo).

    If you don't want to merge a reg file to do it, you can also use REG.EXE which a native tool in Windows 2000; it's not installed by default but it is part of the Support Tools on the CD (x:\support\tools). You can either install the full tools or just extract reg.exe from SUPPORT.CAB. It runs in a cmd window; you can get all the command line parameters in the well-know fashion:


    Registry Console Tool For Windows 2000 - version 2.0
    Copyright (C) Microsoft Corp. 1981-1999.  All rights reserved

    REG Operation [Parameter List]

      Operation  [ QUERY   | ADD    | DELETE  | COPY    |
                   SAVE    | LOAD   | UNLOAD  | RESTORE |
                   COMPARE | EXPORT | IMPORT ]

    Return Code: (Except of REG COMPARE)

      0 - Succussful
      1 - Failed

    For help on a specific operation type:

      REG Operation /?


      REG QUERY /?
      REG ADD /?
      REG DELETE /?
      REG COPY /?
      REG SAVE /?
      REG RESTORE /?
      REG LOAD /?
      REG UNLOAD /?
      REG COMPARE /?
      REG EXPORT /?
      REG IMPORT /?

    C:\>reg delete /?

    Registry Console Tool For Windows 2000 - version 2.0
    Copyright (C) Microsoft Corp. 1981-1999.  All rights reserved

    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

      REG DELETE \\ZODIAC\HKLM\Software\MyCo /v MTU
        Deletes the registry value MTU under MyCo on ZODIAC

    OK: I'm finally done. Hope this helps.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
    In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now