0

我要做的是让批处理脚本返回程序的卸载链接。所以基本上我想要这样的东西:

Select UninstallString from HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall where DisplayName='Sublime Text 1.0"

我在用着

reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall /S^|find " DisplayName"

最初获取程序列表,然后将其放入菜单中,然后选择要卸载的程序,它应该转到 HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall 中的该程序的注册表并获取它的 UninstallString价值

4

2 回答 2

1

尝试这个:

@echo off&setlocal enabledelayedexpansion
set "regroot=HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
set "file=%~dpn0.txt"

set /a fcount=0
for /f "delims==" %%i in ('set $ 2^>nul') do set "%%i="
if exist "%file%" (
    for /f "usebackqtokens=1*delims=|" %%i in ("%file%") do (
        set /a fcount+=1
        set "$d%%j=%%j"
        set "$u%%j=%%i"
    )
    goto:menu
)
echo(building "%file%", please wait
for /f "delims=" %%i in ('reg query "%regroot%"') do (
    set "DN="& set "US="
    for /f "tokens=2*" %%j in ('reg query "%regroot%\%%~ni" /v DisplayName 2^>nul^|find /i "DisplayName"') do set "DN=%%~k"
    for /f "tokens=2*" %%j in ('reg query "%regroot%\%%~ni" /v UninstallString 2^>nul^|find /i "UninstallString"') do set "US=%%~k"
    if not "!DN!"=="" if not "!US!"=="" if not defined $d!DN! (
        >>"%file%" echo(!US!^|!DN!
        set /a fcount+=1
        set "$d!DN!=!DN!"
        set "$u!DN!=!US!"
        <nul set/p"=."
    )
)
echo(
:menu
echo(%fcount% programs with uninstall strings found.
:loop
set /a pcount=0
set "program="
set /p "program=type a program name (q=quit): "
if not defined program goto:loop
if "%program%"=="q" goto:eof
echo(
for /f "tokens=2delims==" %%i in ('set $d ^|findstr !program! 2^>nul') do (
    echo(%%i
    echo(!$u%%i!
    echo(
    set /a pcount+=1
)
if %pcount% equ 0 (echo(!program! not found.) else echo(%pcount% program(s^) found.
goto:loop

您可以使用某些findstrREGEX 功能(例如,/i用于不区分大小写的搜索)。请注意:要搜索所有以“M”开头的程序,您可以使用"^$dM"/b $dM。可搜索的字符串总是有一个前导$d

于 2013-04-11T23:01:53.940 回答
0

试试这个“双线”:

for /f "tokens=7 delims=\" %%a in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /S /F "MySoftware" ^| find "{"') do set ProgramUninstallRegKey=%%a
for /f "skip=1 tokens=3*" %%a in ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%ProgramUninstallRegKey% /V "UninstallString"') do set ProgramUninstallString=%%a %%b
于 2017-03-24T10:54:28.043 回答