Search code examples
windowsbatch-fileregistry

Deleting a registry beginning with XXX


First time posting so go easy on me. :)

I need to delete a registry that begins with 'MikePike' for example.

It needs to check if anything that has this in its name, because 'MikePike' will contain numbers after it, in no specific order. I cant just delete 'MikePike' because it would be different every time.

This needs to be done in a .bat file as I'm trying to make my teams' job easier, and we cannot install any additional software.

I did look at using wildcards but not sure if you can use this for registry edits.

Below is a snippet of what I have in my .bat:

`REGEDIT4

REGEDIT.EXE /E  C:/rs-pkgs/REGTEST.REG
REGEDIT.EXE /E  c:/rs-pkgs/SEARCHREG.REG

@echo off
pushd "%temp%"
makecab /D RptFileName=~.rpt /D InfFileName=~.inf /f nul >nul
for /f "tokens=3-7" %%a in ('find /i "makecab"^<~.rpt') do (
   set "current-date=%%e%%b%%c"
   set "current-time=%%d"
   set "weekday=%%a"
   set "dateandtime=%%e%%b%%c-%%d
)
del ~.*
popd

echo Todays date is the following: %weekday% %current-date% %current-       time%

rename C:\rs-pkgs\REGTEST.REG %current-date%.REG


reg delete HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\services\GxEvMgrC(Instance001) /f

reg delete HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\services\GxClusPlugIn (234435) (7532)'

The last reg key will have random numbers in it, I have hit brick wall... :(

Any help is greatly appreciated, and will save countless hours :D

Thanks, Michael


Solution

  • @echo off
    
    for /f  %%a in (' 
        reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\services" ^|
        find "GxClusPlugIn"
    ') do (
         set "regs=%%a"
    )
    
    echo %regs%
    reg delete "%regs%"