如何通过匹配值查找注册表文件夹

How to find registry folder by match in it`s value

我正在编写一个批处理文件来搜索注册表。 我需要在 HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products 中找到 ProductName 键等于“MyProduct”的文件夹。 我需要找到这个文件夹并删除它。

我要删除的文件夹如下所示:HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\ProductsA0614C849C672CF0A680DCFA3921735

在此示例中,将 MyProduct 更改为您实际的 ProductName 字符串,保留结束双引号不变,在行 4:

@Echo Off
SetLocal EnableExtensions

Set "App=MyProduct"
Set "Key=HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products"

For /F "Delims=" %%G In ('^""%SystemRoot%\System32\reg.exe" Query "%Key%" /S /F
 "%App%" /D /E 2^>NUL ^| "%SystemRoot%\System32\findstr.exe" /I /R /X
 "%Key:\=\%\[^^^\]*"^"'
) Do Echo="%SystemRoot%\System32\reg.exe" Delete "%%G" /F ^>NUL
Pause

以上将仅打印您打算 运行 删除的行。一旦您满意它是正确的,要实际删除它,请将代码更改为以下内容(记住再次更改您的 ProductName 字符串)。 请注意,当您从 HKEY_LOCAL_MACHINE 中删除密钥时,您很可能需要 运行 此脚本提升权限,或者作为具有足够权限的用户执行此操作。:

@Echo Off
SetLocal EnableExtensions

Set "App=MyProduct"
Set "Key=HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Products"

For /F "Delims=" %%G In ('^""%SystemRoot%\System32\reg.exe" Query "%Key%" /S /F
 "%App%" /D /E 2^>NUL ^| "%SystemRoot%\System32\findstr.exe" /I /R /X
 "%Key:\=\%\[^^^\]*"^"'
) Do "%SystemRoot%\System32\reg.exe" Delete "%%G" /F >NUL