also, if the search term needs to be case-insensitive, then add /i to the find command: find/i "\ExpressServer"
Main Topics
Browse All TopicsHi,
I've searched around and found a few solutions for my problem using VBS, but I'd really like to avoid using that method if possible.
I need to remove a pile of separate registry keys (ie: they are not all part of the parent tree, they are all separate keys) that all contain the same word, for example:
HKEY_LOCAL_MACHINE\SOFTWAR
HKEY_LOCAL_MACHINE\SOFTWAR
etc. etc.
So I could go through the batch file like this:
REG DELETE HKEY_LOCAL_MACHINE\SOFTWAR
REG DELETE HKEY_LOCAL_MACHINE\SOFTWAR
etc. etc.
however there are so many of these keys that I don't want to have to do it that way, plus I would be unsure if the uninstaller (that would have been run beforehand) would have removed exactly the same keys as the time before (this will be run many times on many servers).
I found a way to use REG QUERY to return the keys that I need:
REG QUERY HKEY_LOCAL_MACHINE\SOFTWAR
however I cannot work out a way to nest this within the REG DELETE command - I'm quite sure it's not possible.
So how would I go about doing this?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks for the reply knightEknight. It appears to work, however it doesn't actually delete the keys (using your code)!
After doing some reading yesterday, it looks like that any keys that contain other keys need to be recursively removed. So for instance, each of these keys contains another key called Clsid. I didn't realise this would be a problem when I put up the original post.
I suppose I could just append \Clsid, remove that, then remove the parent keys, however what about when I want to use this batch file to remove other keys that may contain different child keys? Is there any way to do this using batchfiles?
OK, after a bit more research and some help from others here, I am using this batch file:
@echo off
if "%1"=="" goto :USAGE
for /f "delims=" %%R in ('REG QUERY "HKLM\SOFTWARE\Classes" /f "%1"') do call :killit %%R
goto :EOF
:killit
REG DELETE %1 /va /f
if errorlevel 1 echo Error %errorlevel%
goto :EOF
:USAGE
echo regquery keyname
echo Where keyname is a subkey of the HKLM\SOFTWARE\Classes key
:EOF
and out of that, I get Error code 1. According to this page http://www.computerhope.co
I am logged in as an Administrator on the computer than the batch file is being run on.
Any ideas?
Still doesn't delete the reg keys but I believe this has to do with something else - but I can see it outputs the commands I want in the correct format. I can't find reg 3.0 (the solution posted by my username is someone else in this company) - but I don't believe that is compatible with Server 2003, and I don't believe it will help anyway. Have had to move on, but will revisit this issue in the near future. Thanks again!
Business Accounts
Answer for Membership
by: knightEknightPosted on 2008-08-19 at 05:08:30ID: 22258997
From a command prompt you can do this:
for /f "delims=" %R in ('REG QUERY HKEY_LOCAL_MACHINE\SOFTWAR E\Classes\ /f ExpressServer ^| find "\ExpressServer"') do @echo REG DELETE "%R" /va /f
From a batch file you need to double-up the % symbols:
for /f "delims=" %%R in ('REG QUERY HKEY_LOCAL_MACHINE\SOFTWAR
In BOTH cases you will need to remove the @echo in order for it to actually perform the delete. (I left the @echo in just so you can see what it will do first, before actually doing it.)