我想知道是否有人可以告诉我如何创建一个批处理文件,如果它存在则从注册表中删除键/值,如果不存在则添加它?
问问题
667 次
2 回答
0
我做了一个功能:
@Echo OFF
:: By Elektro H@cker
REM CALL :REGIF "KEY\SUBKEY"
REM or
REM CALL :REGIF "KEY\SUBKEY" /V "VALUE"
REM Examples:
Call :REGIF "HKLM\Key that fails"
Call :REGIF "HKCU\Software\Microsoft\Windows\Shell\BagMRU"
Call :REGIF "HKCU\Software\Microsoft\Windows\Shell\BagMRU" /V "MRUListEx"
Pause&Exit
:REGIF
REG QUERY %* 1>NUL 2>&1 && (
REG DELETE %* /F 1>NUL
Echo [+] Key deleted: %* | MORE
) || (
REM added value is default SZ type.
REG ADD %* /F >NUL
Echo [+] Key added: %* | MORE
)
GOTO:EOF
于 2012-11-22T05:58:15.467 回答
0
干得好
set name=HKLM\SOFTWARE\key /v value
reg query %name%
if %errorlevel%==0 (
reg delete %name% /f
) else (
if %errorlevel%==1 reg add %name% /d "data" /f
)
于 2012-11-22T13:34:26.650 回答