简体   繁体   English

批处理文件,查询注册表

[英]Batch file, query the registry

Hello People of StackoverFlow, 您好,StackoverFlow的人,

I am trying to query the follow registry location(every folder in here) HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall 我正在尝试查询以下注册表位置(此处的每个文件夹) HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall

In there are random numbers like so: 在里面有这样的随机数:

{071c9b48-7c32-4621-a0ac-3f809523288f}

In each of these random numbers, I need to check if the key 'DisplayName' that is in each of these locations contains a certain text, lets say 'OverFlow'. 在这些随机数的每一个中,我需要检查每个位置中的键“ DisplayName”是否包含特定文本,比如说“ OverFlow”。

I've done some querys but not like this, if anyone can help that would be great! 我已经做了一些查询,但不是这样,如果有人可以帮助的话,那太好了!

EDIT: I've made some progress but am encountering a problem( I have done alot of research...) 编辑:我已经取得了一些进展,但遇到一个问题(我做了很多研究...)

Below is what I have so far: 以下是我到目前为止的内容:

@echo off

setlocal


:RemoveCVCP
set PythonReg=
for /f "tokens=1"  %%A in ('reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s /v "DisplayName" ^| find "Python"') do set "PythonReg=%%A"
if %ERRORLEVEL% neq 0 (
GOTO RemovePyCP)
echo %PythonReg%

endlocal

pause

What I'm trying to do is loop through 'KLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall', and look at the 'DisplayName' key, if the data contains 'Python' then delete it. 我想做的是通过“ KLM \\ SOFTWARE \\ Microsoft \\ Windows \\ CurrentVersion \\ Uninstall”循环,并查看“ DisplayName”键,如果数据包含“ Python”,则将其删除。 and keep going till there are no longer any more. 并继续下去,直到不再有。

Right Now I am testing this with an echo, but it will evetually delete it. 现在,我正在用回显测试它,但是它将迅速删除它。

(I'm just using python as an example, I have already removed everything else that is related to the software I'm trying to remove, this is the last location.) (我仅以python为例,已经删除了与要删除的软件相关的所有其他内容,这是最后一个位置。)

Thanks, Michael 谢谢迈克尔

First, list all values that contain python , two lines will be printed for each entry: 首先,列出所有包含python值,每个条目将打印两行:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{E43BBAEB-4914-44C6-88C0-E7A1DBD20A91}
    DisplayName    REG_SZ    Some application title with python in its name

then delete those keys where the printed value name is DisplayName : 然后删除那些打印值名称为DisplayName键:

@echo off
setlocal enableDelayedExpansion

for /f "tokens=1,2*" %%A in ('^
    reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /s /d /f "python"^
') do (
    if "%%A"=="DisplayName" (
        echo Deleting %%C
        reg delete !key! /f
    ) else (
        set str=%%A
        if "!str:~0,4!"=="HKEY" set key=%%A
    )
)
pause

This code assumes there are no spaces in the key name. 此代码假定键名中没有空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM