使用for循环批量删除完整的注册表项 [英] Batch remove full registry key using for loop
问题描述
我可以使用以下方法找到注册表项:
I can find registry keys using:
REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData /F "Need removed manually Add-In" /S
但是此结果包含子项:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\145BA990C18DA984499E1D1F9A1BD64D
BB02C99E89C99CD4A8CC6A7AA7576194 REG_SZ C:\Program Files (x86)\Need removed manually Add-In\SimonFell\PocketSoap\psDime.dll
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\37AC9AD16C5204A4D9D92967A6699DEE
BB02C99E89C99CD4A8CC6A7AA7576194 REG_SZ C:\Program Files (x86)\Need removed manually Add-In\SimonFell\PocketSoap\pSOAP32.dll
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\DFD1C740E6047204C8387A02138B234A
BB02C99E89C99CD4A8CC6A7AA7576194 REG_SZ C:\Program Files (x86)\Need removed manually Add-In\SimonFell\PocketSoap\pocketHTTP.dll
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\F3A3DDBA307ACB945868E32C44414A5E
BB02C99E89C99CD4A8CC6A7AA7576194 REG_SZ C:\Program Files (x86)\Need removed manually Add-In\SimonFell\PocketSoap\psProxy.dll
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\BB02C99E89C99CD4A8CC6A7AA7576194\InstallProperties
DisplayName REG_SZ Need removed manually Add-In
搜索结束:找到5个匹配项.
End of search: 5 match(es) found.
当我尝试通过脚本删除使用
When I try to delete using with a script
FOR /f "delims=" %%a IN ('REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData /F "Need removed manually Add-In" /S') DO REG delete "%%a" /f
我成功删除了第一个全键,但是之后,我得到了一个错误,因为脚本试图删除带有字符串详细信息的第二行:
I delete first full key successful but after I that, I get an error because the script is trying to delete the second line with string detail:
$ REG delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\145BA990C18DA984499E1D1F9A1BD64D" /f
The operation completed successfully.
$ REG delete " BB02C99E89C99CD4A8CC6A7AA7576194 REG_SZ C:\Program Files (x86)\Need removed manually Add-In\SimonFell\PocketSoap\psDime.dll" /f
ERROR: Invalid key name.
Type "REG DELETE /?" for usage.
如何仅删除实际密钥并避免此错误?
How can I delete only the actual keys and avoid this error?
推荐答案
您可以将findstr
并入查询中,并排除使用/V
单词REG_SZ
以及搜索字符串完成消息.
You can incorporate findstr
in your query and exclude using /V
the word REG_SZ
as well as the search string completion message.
@echo off
for /f "delims=" %%a IN ('REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData /F "Need removed manually Add-In" /S ^| findstr /V "REG_SZ" ^| findstr /V "End of Search"') DO echo REG delete "%%a" /f
在这里我回显delete命令,因此您可以先对其进行测试.一旦高兴,只需删除此部分echo REG delete "%%a" /f
Here I echo the delete command, so you can test it first. Once happy, simply remove the echo from this part echo REG delete "%%a" /f
这篇关于使用for循环批量删除完整的注册表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!