Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
2  
Win 2k is EOL. Time to upgrade! –  MDMarra Jan 19 '12 at 12:00
add comment

2 Answers

What about

 Reg Delete HKLM\SOFTWARE\Microsoft\CurrentVersion\SampleKey

?

Type

 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! –  nullity 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
1  
@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
show 2 more comments

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
add comment

Your Answer

 
discard

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.