Solved

bat file to remove registry keys/entries

Posted on 2004-10-08
15
14,511 Views
Last Modified: 2008-09-30
I need to write a simple bat file to remove some registry keys/entries.  any ideas?
0
Comment
Question by:Martin_C
  • 7
  • 6
  • 2
15 Comments
 
LVL 9

Accepted Solution

by:
DrWarezz earned 125 total points
ID: 12263283
What OS are you on? If it's Win2000 or WinXP, then just use reg.exe:

type:  reg /?   at command prompt for more info. However, here's all the info you need:

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

Examples:

  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


An example of using this in a batch file is:

@echo off
:: Delete Registry Key:
REG DELETE HKLM\SOFTWARE\Microsoft\aKey

::Delete Registry Entry/Value:
REG DELETE HKLM\SOFTWARE\Microsoft\AnotherKey /v anEntry


I hope that helps :)
[r.D]
0
 
LVL 2

Author Comment

by:Martin_C
ID: 12263449
great, that's what I was looking for.  let me write it up and I'll hook you up with the points when I get it working  :)
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12263461
Okay, let me know if you have any problems.
8-)
0
 
LVL 2

Author Comment

by:Martin_C
ID: 12263502
Ok, just to make sure I got this right, this is what I have:


REG DELETE HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9A861F26-E6A5-4ABE-A590-8EE405C1B612}

REG DELETE HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{48F45200-91E6-11CE-8A4F-0080C81A28D4}

REG DELETE HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{771A9DA0-731A-11CE-993C-00AA004ADB6C}

REG DELETE HKEY_LOCAL_MACHINE\SOFTWARE\TrendMicro

REG DELETE HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tmfilter

REG DELETE HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tmntsrv

REG DELETE HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Vsapint

REG DELETE HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v "Pop3trap.exe"="\"E:\\Program Files\\Trend Micro\\PC-cillin 2000\\Pop3trap.exe\"

REG DELETE HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v "WebTrapNT.exe"="\"E:\\Program Files\\Trend Micro\\PC-cillin 2000\\WebTrapNT.exe\"


The source for this is from here:
http://it.trendmicro-europe.com/enterprise/support/knowledge_base_detail.php?solutionId=6382

under win NT / 2000
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12263521
Very almost. You included the data of the values in the last 2 lines. Which you don't need to do. Use this though:


::------------------------------ FileName.bat -----------------------------------::
@echo off
REG DELETE HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9A861F26-E6A5-4ABE-A590-8EE405C1B612}

REG DELETE HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{48F45200-91E6-11CE-8A4F-0080C81A28D4}

REG DELETE HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{771A9DA0-731A-11CE-993C-00AA004ADB6C}

REG DELETE HKEY_LOCAL_MACHINE\SOFTWARE\TrendMicro

REG DELETE HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tmfilter

REG DELETE HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tmntsrv

REG DELETE HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Vsapint

REG DELETE HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Pop3trap.exe

REG DELETE HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v WebTrapNT.exe
::------------------------------ FileName.bat -----------------------------------::

:) gL,
[r.D]
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12263533
You may also want to add the '/f' parameter onto the end of each line, so that it forces deletion without prompting you each time. :)
0
 
LVL 2

Author Comment

by:Martin_C
ID: 12263573
great thank you! . . backing up registry now . . .  :)
0
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.

 
LVL 9

Expert Comment

by:DrWarezz
ID: 12263587
:) Okay.

Also;
Here's a little tip (for future reference), for if you want to be smart, and save yourself some time:

If you want to remove a LARGE list of registry keys/values, then save yourself time, by; not having to add the "REG DELETE" before each key, instead, create a file listing each one, like so:

------8<---------- FileName.txt ----------------------
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9A861F26-E6A5-4ABE-A590-8EE405C1B612}
HKEY_LOCAL_MACHINE\Software\Classes\CLSID\{48F45200-91E6-11CE-8A4F-0080C81A28D4}
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v Pop3trap.exe
------8<---------- FileName.txt ----------------------

Then, you simply run this batch file, and it will delete all of those values/keys:

::----------------- FileName.bat ----------------------::
@echo off
cls
echo.
echo Deleting Registry Keys^/Values ...

set FILE=FileName.txt
for /f "tokens=* delims=" %%R in (%FILE%) do call :DELETE %%R
exit

:DELETE
REG DELETE %1 /F
exit /b
::----------------- FileName.bat ----------------------::

Now, i haven't tested that, but it's SURE to work  :)
[r.D]
0
 
LVL 2

Author Comment

by:Martin_C
ID: 12263910
Ok, didn't work . . .  BAt file ran and disapeared, but reg entries still there . .

I tried entering one line in a command  window and got this error "'REG' is not recognized as an internal or external command, operable program or batch file."

So I tried using REGEDIT instead of just REG and I got a popup window that said "are you sure you want to add "DELETE" to the registry? I said yes and it said unable to add entry, then another popup said cannont delete yada yada entry,  error opening file.

It's friday, and I gotta run, but if you have any other thoughts please let me know.  I'll take another stab at it on tuesday.  Thanks again for the help though.
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12265911
Ah.. the problem is: you don't have reg.exe installed on your computer... (note, reg.exe is different from regedit.exe).
What OS are you on? It would appear that you're not on Windows 2000 or Windows XP...?

You could either download reg.exe from Microsoft, or, refer to creating a registry file (*.reg). Which you can use to delete the registry keys/values.

Choose which one, and let me know on Tuesday, I'll then get you some info on which ever one you choose :)

Best of luck,
[r.D]
0
 
LVL 5

Assisted Solution

by:naiea1231
naiea1231 earned 50 total points
ID: 12266183
Reg.exe (Reg) is a native command in Windows 2000 and higher (including XP), however, if your running an older version of windows it can be found in the NT 4.0 resource kit (http://www.microsoft.com/ntserver/nts/downloads/recommended/ntkit/)

However, if you are running Win2k or greater, then it might be a matter of copying reg.exe to the directory where the batch file is being run.
0
 
LVL 2

Author Comment

by:Martin_C
ID: 12287869
Ok, I'm back.   I will be running this on several win2k machines.   I put the bat file and reg.exe on the network drive, and ran it.  Everything worked!  Well, on the test machine anyway.  but I've got the idea now.  This will save me many hours.  Thanks for the help.  

It was a matter of having the reg file in the same directory.
0
 
LVL 2

Author Comment

by:Martin_C
ID: 12287922
I increased the points and split them, DrWarezz gets the original 125pts for all the effort, but I gave some to naiea1231 for the final tip that made it work.  Thanks again!
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12290233
;) ThanQ.
0
 
LVL 5

Expert Comment

by:naiea1231
ID: 12294654
Thanks, glad it worked out for you, always great to have a batch file simplifying lots of manual work
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 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