Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm want to edit an already production .cmd script file, to have the script delete a certain registry key in the Windows registry.

Firstly, is this even possible, and secondly (if that's not possible), could I create a .reg file and execute that file from with the .cmd file???

From within the .cmd script is not working:

del "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\CurrentVersion\SampleKey]"

This method hasn't worked for me either:

cmd "\\networkdrive\regfiles\deleteSampleKey.reg"

Then from within the reg file:

Windows Registry Editor Version 5.00
-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

NOTE: I am using Windows 2000 x86 Operating System. I'm not sure whether this will have any effect on how things work?

share|improve this question
Win 2k is EOL. Time to upgrade! – MDMarra Jan 19 '12 at 12:00

What about

 Reg Delete HKLM\SOFTWARE\Microsoft\CurrentVersion\SampleKey



 reg Delete /? 

for more info

share|improve this answer
The method from @nullity will also work, but I prefer this method for simple changes as it's easily readable. Use the .reg approach when you want to make large changes to the registry. The .reg method also allows you to have one .reg file which deletes and adds keys etc – Dan Jan 19 '12 at 11:27
@sgmoore when I type 'reg Delete /?' in cmd I'm getting an error stating that 'reg' is not recognised as an internal or external command.... – Derek Jan 19 '12 at 11:36
What/where are you executing this? What about simply typing reg /?? REG should be available anywhere command prompt is! I agree that the REG command is more readable, and I've edited my answer to include it as the preferred method. I was fixated on the regedit import from the posters suggestion! – Josh Atkins Jan 19 '12 at 11:45
@nullity thanks for the edit... Strange - I have tried the reg command from my 2008 server machine and its fine. However from my Windows 2000 machine it does not work??? is there something I should be enabling here? – Derek Jan 19 '12 at 11:52
@nullity found out the problem (with your assistance of course!! :)) reg.exe is not installed by default on Win2k. However you can install it manually from the CD via Support/Tools/Setup.exe. All working now :) Thanks. – Derek Jan 19 '12 at 12:04

You need to execute regedit.exe (with a /s switch for silent) instead of simply cmding the .reg.

regedit /s "\\networkdrive\regfiles\deleteSampleKey.reg"

should do what you want (untested).

EDIT: As per @sgmoore 's answer the preferred method should be using REG, unless you have a large number of entries to clean up.

reg /?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.