Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems finding the value of registry keys
    text
    copied!<p>I'm attempting to make a batch script to uninstall various programs with little involvement from the user (Only saying I want to uninstall Group A (Say, Google Chrome and Microsoft Office)), Partially for work and partially for fun and practice. This itself isn't impossible, I can already do this by calling msiexec and pointing it to the uninstall location in the registry (msiexec /x {xxxxx-xxxxx-xxxxxx-xxxx}).</p> <p>The only problem with this is that this means that whenever the program changes registry keys, as will often happen with updates, I have to find the path again. So, I'm trying to run a piece of code that will search through the HKLM\SOFTWARE\Mincrosoft\Windows\CurrentVersion\Uninstall registry location, and whenever the DisplayName returns a certain value, not necessarily exact (Say "Chrome"), it stores the registry location?(The part that would be put in {xxxxxxx-xxxxxxx-xxxxxxx-xxxxxx}).</p> <p>This way, the program simply finds the programs and stores their locations so that they can be uninstalled with it as a variable. I have tried, but as far as I know using reg query requires the full location. using reg query HKLM /f returns no results. I've tried a whole range of different workarounds, but nothing seems to work.</p> <p>Here is a basic version of my code (I am neglecting to post the full version because much of it is repeated. It's mostly just case where's and if then statements)</p> <pre><code>@echo off :start echo Hello echo. 1: Uninstall Chrome set /p choice="Enter Choice: " if "%choice%"=="1" goto uninstall_chrome :uninstall_chrome reg query HKLM /f Chrome /t REG_SZ ::msiexec /x{uninstall location for the program} </code></pre> <p>Thanks.</p> <p>::UPDATE::</p> <p>I figured it out. By using some of Rob van der Woude's code, I am now able to do it. The code to do so is:</p> <pre><code>CALL :Uninstall "Program Name" :Uninstall SETLOCAL ENABLEDELAYEDEXPANSION FOR /F "tokens=* %%A IN ('REG QUERY HKLM\SOFWARE\Microsoft\Windows\CurrentVersion\Uninstall /F "%~1" /D /S 2^&gt;NUL ^| FINDSTR /R /B /C:"HKEY_"') DO ( REG QUERY "%%~A" /F DisplayName /V /E | FINDSTR /R /I /C:" DisplayName .* .*%~1" &gt;NUL 2&gt;&amp;1 FOR /F "tokens=2*" %%B IN ('REG QUERY "%%~A" /F DisplayName /V /E 2^&gt;NUL ^| FIND /I " DisplayName "') DO ECHO Program Name = %%C FOR /F "tokens=7 delims=\" %%B IN ("%%~A") DO ECHO Unique Identifier = %%B FOR /F "tokens=2*" %%B IN ('REG QUERY "%%~A" /F UninstallString /V /E ^| FIND /I " UninstallString "') DO %%C /qb ) ENDLOCAL </code></pre> <p>This will output the programs name and unique identifier, then uninstall the program, without user input ("Do you want to uninstall x?")</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload