Dk 68 61 63 6b
Dk 68 61 63 6b

Reputation: 65

Deleting Registry entries using reg delete

I am trying to delete registry values using reg delete in a batch command. The problem I am having is that I can't delete the value. Here is what I am trying:

REG DELETE "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports\" /v C:\convertdoc\output\SilentPrintTemp\126017829image-gif3.ps

Ideally I wanna remove all entries with:

REG DELETE "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports\" /v  C:\convertdoc\output\SilentPrintTemp\*.ps

I have tried it in a few different ways and with different parameters. Normally the double "" stops the command at the end of the key. So maybe my syntax is wrong?

Upvotes: 1

Views: 11135

Answers (1)

rojo
rojo

Reputation: 24466

Edit:

Save this with a .bat extension and run it:

@echo off
setlocal
set "ports=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports"

rem get only the first token of each line of "reg query"
for /f %%I in (
    'reg query "%ports%"'
) do (
    echo(%%I | findstr /i "c:\\convertdoc\\output\\silentprinttemp\\.*\.ps" >NUL && (
        rem (if "findstr" didn't exit with an abnormal error code)
        echo Deleting item %%I
        reg delete "%ports%" /v "%%I" /f
    )
)

Upvotes: 1

Related Questions