使用reg delete删除注册表项

时间:2013-04-16 18:17:52

标签: batch-file registry dos

我正在尝试使用批处理命令中的reg delete删除注册表值。我遇到的问题是我无法删除该值。这是我正在尝试的:

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

理想情况下,我想删除所有条目:

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

我已经尝试过几种不同的方式和不同的参数。通常,双“”会在键的末尾停止命令。也许我的语法错了?

1 个答案:

答案 0 :(得分:1)

修改

使用.bat扩展程序保存并运行它:

@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
    )
)