简体   繁体   中英

Batch file, query the registry

Hello People of StackoverFlow,

I am trying to query the follow registry location(every folder in here) 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'.

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

Thanks, Michael

First, list all values that contain python , two lines will be printed for each entry:

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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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