使用批处理脚本在卸载中搜索注册表值

时间:2017-10-18 20:27:45

标签: windows batch-file

如果你问我为什么使用Batch而不是PS或其他东西,这就是它的制作方式,我无法改变它。请为批次提供任何帮助。

长话短说,我有一个为我们公司运行的批处理程序。它将由硬件部门用于所有计算机上的用户配置。

我已经完成了整个部分,但遇到了一个问题。我有一个专门用于根据注册表的卸载部分检查程序是否存在的部分。通常,大多数程序始终保持GUID相同。显然,Screen Connect决定更改他们的GUID,正如我在6台不同的计算机上找到的那样,卸载中的GUID不同。

我知道如何在一个键中搜索一个值,即I.E。

使用此示例,AnyConnect使用文本键而不是GUID {XXX}

load

但是,我想知道是否有办法检查密钥中密钥的值。

即。 :reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Cisco AnyConnect Secure Mobility Client cls if %ERRORLEVEL% EQU 0 SET AnyConnect=Yes if %ERRORLEVEL% EQU 1 SET AnyConnect=No

几乎像某些东西一样:

....CurrentVersion\Uninstall\{GUID} "Value"

或者不管它是什么,因为我不知道使用哪种开关。

这里的问题是它会搜索没有值的Uninstall,因为它是GUID的父文件夹。

由于我不知道GUID会是什么,有没有办法在一个reg Query命令中搜索\ Uninstall下的所有键及其值?

如果这是有道理的。

如果您有任何问题,请与我们联系。

beta编辑代码。

这有些陈旧,所以有一些错误,但你会得到一般的想法。

for /f "tokens=4" %%a in ('reg query "HKEY_LOCAL_MACHINE.......\Uninstall\"  /V *******  ^|findstr /ri "ScreenConnect"') do set /a ID=%%a + 0
@echo OFF

:check_Permissions
cls
    echo Administrative permissions required. 
    net session >nul 2>&1
    if %errorLevel% == 0 (
        echo Success: Administrative permissions confirmed. && goto MoveForward
    ) else (
        echo Failure: Please re-run as an Administrator.
        pause
        exit
    )
goto :check_Permissions
    pause

:MoveForward
cls
echo Admininstrative Privs Confirmed
pause
cls

echo ---------------------------------------------------------------
echo                          Current Info
echo ---------------------------------------------------------------
echo.
systeminfo | findstr /B /C:"Domain"
echo User Name:                   %username%
echo.
echo.
for /f "tokens=9 delims==" %%I in ('WHOAMI /FQDN') do set "Domain=%%I"
set "Line1=Current Domain: %Domain%"
echo.
if "%Domain%"=="XXXXXXXX" goto Name
if NOT "%Domain%"=="XXXXXXXX" echo.
echo Unable to Resolve FQDN. You May need to connect to the domain. 
echo.
echo    ******************Please see Below*********************
echo.
echo If the top shows you are connected to the domain and the username is XXXX
echo You are all set. The FQDN will NOT show up until logged in as a Domain User.
echo.
echo.
echo.
echo.


pause
echo.
echo Remember, if XXXX and Domain were correct, Please Enter N
echo.
:choice
set /P c=Do you want to open the Name/Domain Dialog Box[Y/N]?
if /I "%c%" EQU "Y" goto :AddDomain
if /I "%c%" EQU "N" goto :Name

:addDomain
Start /wait C:\Windows\System32\SystemPropertiesComputerName.exe
pause
goto Name
REM PE Tools Split PE Explorer and PE Resource Tuner into 2 separate Programs FYI
exit


:ChangeHostname

:: Defunct
REM Legacy, Now Running Powershell see C:\XXXXXXXXXX\Config_Bat\Domain_Add.ps1
:: SET /P PCNAME=Please enter your name: 
:: REG ADD HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName /v ComputerName /t REG_SZ /d %PCNAME% /f


pause

:ChangeXXXXPassword
cls
echo Command sent to change XXX Password to XXXX
net user XXX XXXXXXX
echo.
pause
goto :MainMenu

:Name
cls
REM WMIC
for /f "tokens=2 delims==" %%I in ('wmic computersystem get model /format:list') do set "SYSMODEL=%%I"
set "Line1=                          System Model: %SYSMODEL%"
echo %Line1%
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT

if %OS%==32BIT echo                         This is a 32bit operating system
if %OS%==64BIT echo                         This is a 64bit operating system
echo.

for /f "skip=1 delims=" %%A in (
  'wmic bios get smbiosbiosversion'
) do for /f "delims=" %%B in ("%%A") do set "BIOSVer=%%A"
echo                                Bios Version: %BIOSVer%

for /f "skip=1 delims=" %%A in (
  'wmic computersystem get name'
) do for /f "delims=" %%B in ("%%A") do set "compName=%%A"
echo                                Hostname: %compname%
echo.
echo                              Current User: %USERNAME%
echo.
echo If FQDN does NOT appear, please check up top for Domain to verify XXXXXXX
echo                                Fully Qualified Name
whoami /FQDN
echo.
pause


goto :MainMenu
:: Checking if the batch is running with Admin Privs
goto check_Permissions




:MainMenu

Title HWD Depot Thingy



set "Window[1]=Set XXXXPassword"
set "Window[2]=Check MSI Availability"
set "Window[3]=Install Software"
set "Window[4]=Individual Install"
set "Window[5]=Post Config Check"
set "Window[6]=Open XXXXXXXX Folder"
set "Window[7]=Stop and Disable Windows Update Service"
set "Window[8]=Uninstall DDD * Will check for Acrobat XI *"
set "Window[9]=Exit"

set "Message="
cls
echo.%Message%
echo.
echo                              Current User: %USERNAME%
for /f "skip=1 delims=" %%A in (
  'wmic computersystem get name'
) do for /f "delims=" %%B in ("%%A") do set "compName=%%A"
echo                               Hostname %compname%
echo.
echo.
echo       ******Option 1 and 2 Require Batch to be run as an Administrator******
echo.
echo                                ---Main Menu---
echo.
set "x=0"
:MenuLoop
set /a "X+=1"
if defined Window[%x%] (
call echo                             %x%. %%Window[%x%]%%
goto MenuLoop
)
echo.


:Prompt
Set "Input="
set /p "Input=HWD                        Select Which Shell Window: "

:: Validate Input
if not defined Input goto Prompt
set "Input=%Input:"=%"
set "Input=%Input:^=%"
set "Input=%Input:<=%"
set "Input=%Input:>=%"
set "Input=%Input:&=%"
set "Input=%Input:|=%"
set "Input=%Input:(=%"
set "Input=%Input:)=%"
:: No Equals
set "Input=%Input:^==%"
call :Validate %Input%

:: Process
call :Process %Input%
goto End

:Validate
set "Next=%2"
if not defined Window[%1] (
set "Message=Invalid Input: %1"
goto :MainMenu
)
if defined Next shift & goto Validate
goto :eof

:Process
set "Next=%2"
call set "Window=%%Window[%1]%%"

:: Run
if "%Window%" EQU "Set XXXXXX" goto XXXXXXXX
if "%Window%" EQU "Check MSI Availability" goto CheckMSI
if "%Window%" EQU "Install Software" goto Install
if "%Window%" EQU "Individual Install" goto IndividualInstall
if "%Window%" EQU "Post Config Check" goto PCC
if "%Window%" EQU "Open XXXXXXXX Folder" goto IST
if "%Window%" EQU "Stop and Disable Windows Update Service" goto StopWinUpdt
if "%Window%" EQU "Uninstall DDD * Will check for Acrobat XI *" goto :UninstallDDD
if "%Window%" EQU "Exit" goto :eof


:: Dumbass

:: if "%Window%" EQU "All Apps" ( )
:: Need to make this not an option

:: Prevent Double Jeopardy
set "Window[%1]="
if defined Next shift & goto Process
goto :eof

:CheckMSI
cls

if exist "C:\XXXXXXXXXX\SC_ClientSetup_v63134466374.msi" echo SC MSI Exists
if NOT exist "C:\XXXXXXXXXX\SC_ClientSetup_v63134466374.msi" echo SC MSI NULL
if exist "C:\XXXXXXXXXX\ampagent-7.1.62-x86_help.XXXXXXXX.com.msi" echo KACE MSI Exists
if NOT exist "C:\XXXXXXXXXX\ampagent-7.1.62-x86_help.XXXXXXXX.com.msi" echo KACE MSI NULL
if exist "C:\XXXXXXXXXX\anyconnect-win-4.4.03034-core-vpn-webdeploy-k9.exe" echo AnyConnect MSI Exists
if NOT exist "C:\XXXXXXXXXX\anyconnect-win-4.4.03034-core-vpn-webdeploy-k9.exe" echo AnyConnect MSI NULL
if exist "C:\XXXXXXXXXX\McAfee Installers\Agent_EPO2.exe" echo McAfee Agent Exe Exists
if NOT exist "C:\XXXXXXXXXX\McAfee Installers\Agent_EPO2.exe" echo McAfee Agent Exe NULL
if exist "C:\XXXXXXXXXX\McAfee Installers\2 Endpoint_Security_10_5_1\setupEP.exe" echo McAfee EPO Exe Exists
if NOT exist "C:\XXXXXXXXXX\McAfee Installers\2 Endpoint_Security_10_5_1\setupEP.exe" echo McAfee EPO Exe NULL
if exist "C:\XXXXXXXXXX\McAfee Installers\3 Adaptive_Threat_Protection_10_5_1\setupATP.exe" echo McAfee ATP Exe Exists
if NOT exist "C:\XXXXXXXXXX\McAfee Installers\3 Adaptive_Threat_Protection_10_5_1\setupATP.exe" echo McAfee ATP Exe NULL
if exist "C:\XXXXXXXXXX\McAfee Installers\4 DXL_Client_3_1_595\dxlsetup.exe" echo McAfee DXL Exe Exists
if NOT exist "C:\XXXXXXXXXX\McAfee Installers\4 DXL_Client_3_1_595\dxlsetup.exe" echo McAfee DXL Exe NULL

pause

goto :MainMenu

:StopWinUpdt
cls
echo Processing Windows Update Stop and Disable
net stop wuauserv
echo Processing Disable Command
sc config wuauserv start= disabled
echo Windows Update "Wuauserv" has been Disabled
pause
goto MainMenu

:Install


REM Query Screen Connect Exist

reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{E8ABFA22-897F-4FCB-902A-4DCD400B53DC}
REM Error level 0 means installed
REM Error Level 1 Means Not Installed

if %ERRORLEVEL% EQU 0 SET SC=Yes
if %ERRORLEVEL% EQU 1 SET SC=No

REM Query KACE Exist
reg query HKLM\Software\WOW6432Node\Dell\KACE
cls

REM Error level 0 means installed
REM Error Level 1 Means Not Installed

if %ERRORLEVEL% EQU 0 SET KACE=Yes
if %ERRORLEVEL% EQU 1 SET KACE=No

REM Query Any Connect

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Cisco AnyConnect Secure Mobility Client
cls

if %ERRORLEVEL% EQU 0 SET AnyConnect=Yes
if %ERRORLEVEL% EQU 1 SET AnyConnect=No



Rem Query McAfee Agent

reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{80684F9A-6B01-4F3F-A8C7-C4B7BDF072F1}
cls

if %ERRORLEVEL% EQU 0 SET MAgent=Yes
if %ERRORLEVEL% EQU 1 SET MAgent=No


Rem Query McAfee Endpoint

reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{4F574B83-3AE0-419F-8A3B-985C389334B4}
cls

if %ERRORLEVEL% EQU 0 SET Endpoint=Yes
if %ERRORLEVEL% EQU 1 SET Endpoint=No


Rem Query McAfee Adaptive Thread Protection

reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{80B1F696-3C8F-4BBC-BD07-86CF0E37FDD2}
cls

if %ERRORLEVEL% EQU 0 SET McAfeeAdaptiveThreatProtection=Yes
if %ERRORLEVEL% EQU 1 SET McAfeeAdaptiveThreatProtection=No


Rem Query McAfee Data Exchange Layer

reg query HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{8f28453c-bec7-4d47-8152-3b8b40238dec}
cls

if %ERRORLEVEL% EQU 0 SET McAfeeDataExchangeLayer=Yes
if %ERRORLEVEL% EQU 1 SET McAfeeDataExchangeLayer=No



REM Query Standard X

reg query HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-F400-BA7E-000000000005}
cls

if %ERRORLEVEL% EQU 0 SET StandardX=Yes
if %ERRORLEVEL% EQU 1 SET StandardX=No

REM Query Standard XI

reg query HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-FFFF-7760-000000000006}
cls

if %ERRORLEVEL% EQU 0 SET StandardXI=Yes
if %ERRORLEVEL% EQU 1 SET StandardXI=No


REM We have to Grab the Dword, which is in Hex, and Convert it to Decimal, and store it as a Var

for /f "tokens=4" %%a in ('reg query "HKEY_CURRENT_USER\SOFTWARE\FS StreetSmart\Field Sales Professional"  /V "salesperson ID"  ^|findstr 

/ri "Salesperson ID"') do set /a ID=%%a + 0

REM Output all Results

:ProgramsListed
cls
echo.
echo Program list
echo.
echo SC Installed:                 %SC%
echo Kace Installed:               %Kace%
echo AnyConnect Installed:         %AnyConnect%
echo McAfee Agent Installed:       %MAgent%
echo Endpoint Installed:           %Endpoint%
echo McAfeeAdaptiveThreatProtect:  %McAfeeAdaptiveThreatProtection%
echo McAfee Data Exchange Layer:   %McAfeeDataExchangeLayer%
echo Adobe Standard X Installed:   %StandardX%
echo Adobe Standard XI Installed:  %StandardXI%
echo.
echo.
echo User:             %USERNAME%
echo XXX Sales Person ID:     %ID%
echo.
echo.
echo.



:Installchoice
set /P c=Do you want to add to Install Non-installed Software[Y/N]?
if /I "%c%" EQU "Y" goto :InstallSoft
if /I "%c%" EQU "N" goto :MainMenu

goto :ProgramsListed
:InstallSoft

REM Query Screen Connect
reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{E8ABFA22-897F-4FCB-902A-4DCD400B53DC}
cls

if %ERRORLEVEL% EQU 0 Set SC=Yes
if %ERRORLEVEL% EQU 1 Set SC=No


REM Query KACE Exist
reg query HKLM\Software\WOW6432Node\Dell\KACE
cls

REM Error level 0 means installed
REM Error Level 1 Means Not Installed

if %ERRORLEVEL% EQU 0 SET KACE=Yes
if %ERRORLEVEL% EQU 1 SET KACE=No

REM Query Any Connect

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Cisco AnyConnect Secure Mobility Client
cls

if %ERRORLEVEL% EQU 0 SET AnyConnect=Yes
if %ERRORLEVEL% EQU 1 SET AnyConnect=No



Rem Query McAfee Agent

reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{80684F9A-6B01-4F3F-A8C7-C4B7BDF072F1}
cls

if %ERRORLEVEL% EQU 0 SET MAgent=Yes
if %ERRORLEVEL% EQU 1 SET MAgent=No


Rem Query McAfee Endpoint

reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{4F574B83-3AE0-419F-8A3B-985C389334B4}
cls

if %ERRORLEVEL% EQU 0 SET Endpoint=Yes
if %ERRORLEVEL% EQU 1 SET Endpoint=No


Rem Query McAfee Adaptive Thread Protection

reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{80B1F696-3C8F-4BBC-BD07-86CF0E37FDD2}
cls

if %ERRORLEVEL% EQU 0 SET McAfeeAdaptiveThreatProtection=Yes
if %ERRORLEVEL% EQU 1 SET McAfeeAdaptiveThreatProtection=No


Rem Query McAfee Data Exchange Layer

reg query HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{8f28453c-bec7-4d47-8152-3b8b40238dec}
cls

if %ERRORLEVEL% EQU 0 SET McAfeeDataExchangeLayer=Yes
if %ERRORLEVEL% EQU 1 SET McAfeeDataExchangeLayer=No



REM Query Standard X

reg query HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-F400-BA7E-000000000005}
cls

if %ERRORLEVEL% EQU 0 SET StandardX=Yes
if %ERRORLEVEL% EQU 1 SET StandardX=No

REM Query Standard XI

reg query HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-1033-FFFF-7760-000000000006}
cls

if %ERRORLEVEL% EQU 0 SET StandardXI=Yes
if %ERRORLEVEL% EQU 1 SET StandardXI=No

if /I "%SC%" EQU "No" goto :InstallSC
if /I "%SC%" EQU "Yes" echo Screen Connect Already Installed
if /I "%Kace%" EQU "No" goto :InstallKace
if /I "%Kace%" EQU "Yes" echo Kace Already Installed
if /I "%AnyConnect%" EQU "No" goto :InstallAnyC
if /I "%AnyConnect%" EQU "YES" echo AnyConnect Already Installed
if /I "%MAgent%" EQU "Yes" echo McAfee Agent Already Installed
if /I "%MAgent%" EQU "No" goto :InstallMAgnt
if /I "%Endpoint%" EQU "Yes" echo Endpoint Already Installed
if /I "%Endpoint%" EQU "No" goto :InstallEPO
if /I "%McAfeeAdaptiveThreatProtection%" EQU "Yes" echo McAfee Adaptive Threat Protection Already Installed
if /I "%McAfeeAdaptiveThreatProtection%" EQU "No" goto :InstallATP
if /I "%McAfeeDataExchangeLayer%" EQU "Yes" echo McAfee Exchange Data Layer Installed
if /I "%McAfeeDataExchangeLayer%" EQU "No" goto :InstallDXL


pause
goto :MainMenu
Pause

0 个答案:

没有答案