Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do I edit an already-in-production .cmd script file, in order 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, it 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
]
share|improve this question
    
using a .reg file, even from a network drive should work fine. If it isn't, then, I expect it is down to UAC or other security measures. –  William Hilsum Mar 26 '12 at 10:56

2 Answers 2

I would recommend using the REG command, rather than creating and importing .reg files.

reg delete "HKCU\Some\Registry\Path" /f

or

reg delete "HKLM\Some\Registry\Path" /f

These commands can be entered directly into the batch (.cmd) file.

share|improve this answer

I use the following method. This is part of a MRU ripper for Windows XP, that might help. This is the text of a batch file, that is run from CMD or from a shortcut. It creates a registry file using simple echo redirections, then imports it.

REM *** START REGISTRY SHREDDER ***
ECHO CREATING MRU REGISTRY
ECHO .
 ECHO > "%TMP%\MRUKILL.reg" Windows Registry Editor Version 5.00
ECHO >> "%TMP%\MRUKILL.reg" [-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Doc Find Spec MRU]
ECHO >> "%TMP%\MRUKILL.reg" [-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FindComputerMRU]

REM ***  IMPORT THAT REG TO WIPE OUT THEM KEYS AND VALUES ****
regedit "%TMP%\MRUKILL.reg"

I am not a coder, I just do some batch stuff for myself, so I often can't even read what I wrote, but I would use that as a template for doing something else.

The echos are redirected (>) to a file, with the single > for the first redirection, and >> to append to the same file. The - sign is used to remove a registry entry. It would probably be good to leave off the last line, and view the file it created before importing. Importing can be done silently, but I won't do that myself.

Disclaimer: Because a person can do some serious damage to the system removing registry entries, an disk image backup that can return the system when the system fails is necessary.

Proper permissions, elevations, and some entries in the registry will not just allow the user to destroy them, without setting the permissions, because of their importance.

Here is A "ask the user" part, added just for fun.

ECHO
 REM *** ASK the USER FIRST ***  
ECHO  DO YOU WANT TO DELETE REGISTRY MRUS?
SET /P Choice2=type "Y" to Mangle your registry, - -
ECHO . 
IF /I "%Choice2%"=="Y" GOTO SHREDD
ECHO OK WELL THEN I WON'T
ECHO By By 
   REM *** USER DECIDED AGAINST IT ***
ECHO .
PAUSE
GOTO FINISH
share|improve this answer
1  
on Vista + this method will invoke UAC. and user will have to accept or decline this action. Running the script as Admin will bypass that though –  ppumkin Jan 19 '12 at 11:27
1  
you should not use %USERPROFILE%\Local Settings\Temp, but %TMP%. the former works only on english systems –  kinokijuf Jan 19 '12 at 12:41
    
@kinokijuf Feexed, looks much nicer that way too. It was probably set like that to keep it on system disk for me, because I have sent Temps to ramdisk or to data disks at times. –  Psycogeek Jan 19 '12 at 16:08

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.