Searching for Registry Values in Uninstall using Batch Script - windows

If you are asking why am I using Batch and not PS or something else, this is the way it was made, and I cannot change it. Please just any help for batches.
Long story short, I have a batch program that runs for our company. It will be used by the Hardware department for post configuration on all computers going out to the users.
I have completed the entire portion, but ran into one issue. I have a section dedicated to checking whether a program exists based on the uninstall section of the registry. Normally, most programs, keep the GUID the same throughout. Apparently Screen Connect decides to change their GUID, as I found on 6 different computers, a different GUID in the uninstall.
I know how to regquery to search within a key for a value, I.E.
Using this example as AnyConnect uses a text key rather than a GUID {XXX}
: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
But, I was wondering if there is a way to check for values within keys within a key.
I.E. ....CurrentVersion\Uninstall\{GUID} "Value"
ALMOST AS SOMETHING LIKE:
for /f "tokens=4" %%a in ('reg query "HKEY_LOCAL_MACHINE.......\Uninstall\" /V ******* ^|findstr /ri "ScreenConnect"') do set /a ID=%%a + 0
Or whatever it is, as I do not know which switches to use.
The issue here is it would search Uninstall, which has no values, as it is a parent folder for the GUIDs.
Since I do not know what the GUID is going to be, is there a way for me to search all of the keys under \Uninstall and the values of them in one reg Query command?
If that makes sense.
Let me know if you have any questions.
beta Redacted code.
This is somewhat old, so there are a few errors, but you will get the general idea.
#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
Call "C:\XXXXXXXXXX\McAfee Installers\4 DXL_Client_3_1_595\dxlsetup.exe"
pause
:EndInstall
Goto :InstallSoft
goto :eof
:IndividualInstall
Title HWD Depot Thingy
:MainMenuIndiv
set "Window[1]=SC"
set "Window[2]=Kace"
set "Window[3]=Cisco AnyConnect"
set "Window[4]=McAfee Agent"
set "Window[5]=McAfee EPO"
set "Window[6]=McAfee ATP"
set "Window[7]=McAfee DXL"
set "Window[8]=Adobe Standard * PLEASE DO MANUALLY *"
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.
echo ---Main Menu---
echo.
set "x=0"
:MenuLoopA
set /a "X+=1"
if defined Window[%x%] (
call echo %x%. %%Window[%x%]%%
goto MenuLoopA
)
echo.
:PromptA
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 :ValidateA %Input%
:: Process
call :ProcessA %Input%
goto End
:ValidateA
set "Next=%2"
if not defined Window[%1] (
set "Message=Invalid Input: %1"
goto :MainMenuIndiv
)
if defined Next shift & goto ValidateA
goto :eof
:ProcessA
set "Next=%2"
call set "Window=%%Window[%1]%%"
:: Run
if "%Window%" EQU "SC" goto InstallSCb
if "%Window%" EQU "Kace" goto InstallKACEb
if "%Window%" EQU "Cisco AnyConnect" goto InstallAnyCb
if "%Window%" EQU "McAfee Agent" goto InstallMAgntb
if "%Window%" EQU "McAfee EPO" goto InstallEPOb
if "%Window%" EQU "McAfee ATP" goto InstallATPb
if "%Window%" EQU "McAfee DXL" goto InstallDXLb
if "%Window%" EQU "Adobe Standard * PLEASE DO MANUALLY *" goto :IndividualInstall
if "%Window%" EQU "Exit" goto :MainMenu
:InstallSCb
Start /WAIT C:\XXXXXXXXXX\SC_ClientSetup_v63134466374.msi
set /P c=Do you want to Install Screen Connect[Y/N]?
if /I "%c%" EQU "Y" echo Screen Connect Installing
if /I "%c%" EQU "N" goto :InstallKACE
:InstallKACEb
Start /WAIT C:\XXXXXXXXXX\ampagent-7.1.62-x86_help.asmXXXX.com.msi
echo KACE Installing
goto :IndividualInstall
pause
:InstallAnyCb
echo Any Connect Installing
start /WAIT C:\XXXXXXXXXX\anyconnect-win-4.4.03034-core-vpn-webdeploy-k9.exe
Goto :IndividualInstall
REM Installation Function to set up McAfee Agent
:InstallMAgntb
echo Installing McAfee Agent
Start /WAIT "C:\XXXXXXXXXX\McAfee Installers\Agent_EPO2.exe"
Goto :IndividualInstall
:InstallEPOb
echo Installing McAfee Endpoint
Start /WAIT "C:\XXXXXXXXXX\McAfee Installers\2 Endpoint_Security_10_5_1\setupEP.exe"
Goto :IndividualInstall
:InstallATPb
echo Installing McAfee Adaptive Threat Protection
Start /WAIT "C:\XXXXXXXXXX\McAfee Installers\3 Adaptive_Threat_Protection_10_5_1\setupATP.exe"
Goto :IndividualInstall
:InstallDXLb
echo Installing McAfee Data Exchange Layer
Start /WAIT "C:\XXXXXXXXXX\McAfee Installers\4 DXL_Client_3_1_595\dxlsetup.exe"
Goto :IndividualInstall
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
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
:PCC
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
for /f "tokens=4" %%a in ('reg query "HKEY_CURRENT_USER\SOFTWARE\XXXXXXXX\XXXXXXXXXXXXX" /V "salesperson ID" ^|findstr
/ri "Salesperson ID"') do set /a ID=%%a + 0
if %ERRORLEVEL% EQU 0 goto SkipF
if %ERRORLEVEL% EQU 1 echo XXXXXXXXXXXX is Installed BUT not configured for the user.
:SkipF
echo.
echo.
echo ---------------------------------------------------------------
echo Installed Software
echo ---------------------------------------------------------------
echo.
if /I "%SC%" EQU "Yes" echo SC Installed
if /I "%SC%" EQU "No" goto :InstallSC
if /I "%Kace%" EQU "No" goto :InstallKace
if /I "%Kace%" EQU "Yes" echo Kace Installed
if /I "%AnyConnect%" EQU "No" goto :InstallAnyC
if /I "%AnyConnect%" EQU "YES" echo AnyConnect Installed
if /I "%MAgent%" EQU "Yes" echo McAfee Agent Installed
if /I "%MAgent%" EQU "No" goto :InstallMAgnt
if /I "%Endpoint%" EQU "Yes" echo Endpoint Installed
if /I "%Endpoint%" EQU "No" goto :InstallEPO
if /I "%McAfeeAdaptiveThreatProtection%" EQU "Yes" echo McAfee Adaptive Threat Protection Installed
if /I "%Endpoint%" EQU "No" goto :InstallATP
if /I "%McAfeeDataExchangeLayer%" EQU "Yes" echo McAFee Data Exchange Layer Installed
if /I "%Endpoint%" EQU "No" goto :InstallDX
echo.
echo.
echo User: %USERNAME%
echo XXXXXXXXXXX ID: %ID%
echo.
echo ---------------------------------------------------------------------------
echo ALL SOFTWARE INSTALLED
echo ---------------------------------------------------------------------------
pause
cls
REM Query Dell Digital Delivery
reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{693A23FB-F28B-4F7A-A720-4C1263F97F43}
cls
if %ERRORLEVEL% EQU 0 SET DDD=Yes
if %ERRORLEVEL% EQU 1 SET DDD=No
if /I "%DDD%" EQU "Yes" echo NOTICE
echo Dell Digital Delivery is Installed.
set /P c=Would you like to uninstall it[Y/N]?
if /I "%C%" EQU "Y" start /wait C:\Windows\System32\MsiExec.exe /I{693A23FB-F28B-4F7A-A720-4C1263F97F43}
if /I "%c%" EQU "N" goto :MainMenu
pause
goto :MainMenu
goto :eof
:IST
explorer.exe C:\XXXXXXXXXX
pause
goto MainMenu
:UninstallDDD
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 StandardXb=Yes
if %ERRORLEVEL% EQU 1 SET StandardXb=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 StandardXIb=Yes
if %ERRORLEVEL% EQU 1 SET StandardXIb=No
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
:AdobeXCheck
echo Adobe Program Check
echo.
if /I "%Standardxb%" EQU "Yes" echo Adobe Standard X Installed
goto SkipA
if /I "%Standardxb%" EQU "No" goto :AdobeXICheck
pause
:AdobeXICheck
if /I "%StandardXIb%" EQU "Yes" echo Adobe Standard XI Installed
goto SkipA
if /I "%StandardXIb%" EQU "No" goto :NeitherLogic
goto SkipA
:Neitherlogic
if /I "%StandardXIb%" EQU "Yes" echo Adobe Standard X NULL
if /I "%STandardXIb%" EQU "YES" echo Adobe Standard XI Installed
if /I "%StandardXIb%" EQU "No" echo Neither Adobe X nor XI are installed!!!!
echo.
echo Please check above for Adobe Installations
set /P c=Do you still want to uninstall DDD[Y/N]?
if /I "%c%" EQU "Y" goto UninstalDDDnow
if /I "%c%" EQU "N" echo Going back to main menu
Timeout 5
goto MainMenu
:UninstalDDDnow
cls
echo Uninstalling Dell Digital Delivery
echo.
CALL "C:\Windows\System32\MsiExec.exe" /I{693A23FB-F28B-4F7A-A720-4C1263F97F43}
echo.
reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{693A23FB-F28B-4F7A-A720-4C1263F97F43}
cls
if %ERRORLEVEL% EQU 0 SET DDDpost=Yes
if %ERRORLEVEL% EQU 1 SET DDDpost=No
if /I "%DDDpost%" EQU "Yes" echo Dell Digital Delivery is STILL showing Installed. Please check manually
if /I "%DDDpost%" EQU "No" echo Dell Digital Delivery has succesfully been uninstalled!
pause
goto MainMenu
pause

Related

How To Make A Batch Program That Takes what I input into it and to output it into a .txt file

So Basically I wanna make a program in batch that when I start it asks me to log in and ask me for my email what I want is for the program to take what I put Like this example:
Program asks for Email I input email1234#gmail.com program takes that and stores it in a temp dir as Login.txt
I need this so when the user tries to log in again the program looks for Login.txt and immediately logs in the user without them having to start again.
This is the code:
#echo off
:choice
set /P c=Do you have a Account?[Y/N]?
if /I "%c%" EQU "Y" goto :login_succesfully
if /I "%c%" EQU "N" goto :Cannot_Login
goto :choice
:login_succesfully
cls
Color 2
echo "Ok Login To Verify Your Identity To Use This"
cls
:choice
rem Saved in C:\Temp
set /P c=Email?
if /I "%c%" EQU "" goto :Pass
goto :Pass
pause
exit
:Pass
cls
set /P c=Password?
if /I "%c%" EQU "" goto :Download
goto :Download
:Download
cls
echo Thank You Now Starting Example!
TIMEOUT /T 3
Start https://cdn.discordapp.com/attachments/845027712192217159/848817832170749963/Example1234.txt
pause
exit
:Cannot_Login
cls
color C
echo "Please Create a Account and ask a Admin to Manually Verify Who You Are"
pause
exit
For arbitrary login systems that do not require secure protection of the content, the ntfs system offers an alternative to temporary files courtesy of Alternate data streams.
#Echo off & CD /D "%~dp0"
Goto :Main
=====:# Save function
:Save
:# Define variables for retention with a # prefix
:# and output to the !User!_Save.cmd stream by calling this function
(For /f "Delims=" %%G in ('Set #')Do Echo(Set "%%G") >"%~f0:%#User%_Save.cmd"
Exit /B 0
=====:# User input function
:Input <Variable> <Prompt> <Descriptor>
Setlocal EnableDelayedExpansion
Set "%~1="
Set /P "%~1=%~2: "
If Not Defined %~1 (
Echo(%~3 required
Endlocal
Goto :Input
)
For /f "Delims=" %%v in ("!%~1!")Do ( Endlocal & Set "%~1=%%v" )
Exit /B 0
:Main
Setlocal EnableDelayedExpansion
Set "#Status=New"
Cls
:Login
Echo(Existing users:
For /f "Skip=6 Tokens=2 Delims=:" %%G in ('Dir /R "%~f0"^|Findstr /vc:"_Save.cmd"')Do Echo(%%G
Echo(
Call :input #User "Enter your username" "Username"
If /I "!#User!" == "E" Goto :Eof
:Verify
Cls
(More < "%~f0:!#User!") > nul 2>&1 && (
Call :input #Pass "Enter your password" "Password"
For /f "Delims= " %%G in ('More ^< "%~f0:!#User!"')Do Set "Validate=%%~G"
REM case sensitive. Spaces not permitted.
If not "!Validate!"=="!#Pass!" (
Echo(Password invalid. Try again Y/N?
For /F "Delims=" %%G in ('Choice /N /C:YN')Do if "%%G" == "N" Goto :Login
Goto :Verify
)
) || (
Echo(Create user: "!#User!" Y/N?
For /F "Delims=" %%G in ('Choice /N /C:YN')Do if "%%G" == "N" Goto :Login
Call :input #Pass "Enter your password" Password
Call :input PassC "Confirm your password" Password
If not "!#Pass: =!" == "!PassC!" (
Echo(Passwords do not match. Spaces not Permitted.
Pause
Goto :Verify
)
(Echo(!#Pass: =!) 1>"%~f0:!#User: =!" 2>Nul || (
Echo(Invalid Characters in Password.
Goto :Verify
)
Call :Save
)
:ReturnAction
Echo(
Echo([C]ontinue [R]emove User [N]ew Password ?
For /F "Delims=" %%G in ('Choice /N /C:CRN')Do (
If "%%G" == "R" (
Powershell -c "remove-item -path '%~nx0' -Stream '!#User!'"
(Powershell -c "remove-item -path '%~nx0' -Stream '!#User!_Save.cmd'") 2> nul
Goto :Login
)
If "%%G" == "N" (
For /F "UsebackQ Delims=" %%G in ("%~f0:!#User!_Save.cmd")Do %%G
Call :input #Pass "Enter your new password" Password
Call :input PassC "Confirm your new password" Password
If not "!#Pass: =!" == "!PassC!" (
Echo(Passwords do not match. Space not permitted.
Pause
Goto :ReturnAction
)
(Echo(!#Pass: =!) 1>"%~f0:%#User: =%" 2>Nul || (
Echo(Username contains invalid characters.
Timeout /t 3 /Nobreak
Goto :Verify
)
Call :Save
)
)
:# exit delayed expansion environment
Endlocal & Set "#User=%#User%"
:# Load user information from the stream.
For /F "UsebackQ Delims=" %%G in ("%~f0:%#User%_Save.cmd")Do %%G
Echo(Login Successful.
:# The below line is not required. It simply shows the loaded values.
Set #
:# Your script below
Set "#Status=Returned"
Call :Save
Streams use the following syntax:
"filepath:streamname"
Each user has two streams associated with it, %~f0 being the path of the batch file:
"%~f0:!#User!" ; which the password is saved to
"%~f0:!#User!_Save.cmd" ; which is used to store all # prefixed user variables to for later loading
loading is achieved by reading and reassigning each variable stored in the stream using a For /f loop.
To display existing users, a for loop iterates over the output of the Dir command with the /R switch and "%~f0" search term, which gets filtered through the findstr command via a pipe ( with /Vswitch and _Save.cmd match term to remove the _Save.cmd streams from the output ).
Conditional execution || and && are used to control script flow depending on whether streams are succesfully read.
Powershell is used to remove Streams from the batch file when the user indicates they wish to remove their logged in user. (Batch has no native method of removing streams from a file)

Building batch program to monitor, create, and delete battery logs

I am struggling with how to make the Energy-Reporter program save dates and rename the files. I am new to Batch programing. I started to learn this language when my OEMCreate DELL Latitude E5500 battery died after about a year. I am attempting to make a program that allows me to monitor and save battery statistic reports to my computer. I am hoping to add the ability to graph battery degradation over time. I attached the current code below. I need to figure out how to make a CMD based File manager.
#echo OFF
TITLE Energy-Reporter
set CUR_YYYY=%date:~10,4%
set CUR_MM=%date:~4,2%
set CUR_DD=%date:~7,2%
set CUR_HH=%time:~0,2%
if %CUR_HH% lss 10 (
set CUR_HH=0%time:~1,1%
set CUR_AP="AM"
)
if %CUR_HH% GEQ 12 (
set CUR_HH=CUR_HH-12
set CUR_AP="PM"
)
set CUR_NN=%time:~3,2%
set CUR_SS=%time:~6,2%
set CUR_MS=%time:~9,2%
set SUBFILENAME="%CUR_MM%-%CUR_DD%-%CUR_YYYY%_At_%CUR_HH%-%CUR_NN%-%CUR_SS% %CUR_AP%"
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params= %*
echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
IF EXIST "C:\Program Files\Energy-Report\." (
ECHO DIRECTIORY FOUND
) else (
ECHO CREATING "C:\Program Files\Energy-Report\"
mkdir "C:\Program Files\Energy-Report\"
)
COLOR F4
:USER_SELECTER
CLS
ECHO ===============================================================
ECHO Battery logger
ECHO ===============================================================
ECHO Select an option:
Choice /C codq /N /M "[C]reate power log | [O]pen report | [D]elete log | [Q]uit"
If ErrorLevel 4 GoTo :EOF
If ErrorLevel 3 GoTo DELETE_LOG
If ErrorLevel 2 GoTo SAVED_LOGS
If ErrorLevel 1 GOTO REPORT_DATA
PAUSE
GOTO USER_SELECTER
:REPORT_DATA
cd "C:\Program Files\Energy-Report\"
powercfg -energy
REN "Energy-Report.html" "energy-report_%SUBFILENAME%.html"
PAUSE
GOTO USER_SELECTER
:SAVED_LOGS
cd "C:\Program Files\Energy-Report\"
DIR
PAUSE
GOTO USER_SELECTER
:DELETE_LOG
SET /P Entry_name=log to be erased
DELETE "C:\%Program Files%\Energy-Report\%Entry_name%"
PAUSE
GOTO USER_SELECTER
I have uploaded all of the previous versions of the code to my website for those who are interested in the code development.
If I do not get a chance to update the stack overflow version, The latest version is available by running the code snippet.
<embed style="width:100%;height:100%;"src="https://theelectronichandbook.tech/code/downloads/battery-logger-for-windows/latestcode.php?FRAME=iframe"></embed>

Validating Input in Batch File XY######## - Letters and Numbers Combination

I've created a batch/cmd file which executes correctly, but I would like to add a "validation" layer to check for correct input.
The input should be in the format of LETTER-LETTER-######## (Eight Numbers)
I'm more of a Bash person myself so I'm a little lost.
Here is a basic version of what I am using.
echo Please Input like so XY########
set /P INPUT=Type input: %=%
Ok. Here we go...
There is no way to do what you want if you read the input via set /P command. In this case you may test the input afterwards and repeat it until be correct...
To check the input at same time it is being typed you need to read and test each character individually. There are several ways to do that. The simplest one is based on choice command:
#echo off
setlocal EnableDelayedExpansion
echo Please Input like so XY########
set /P "=Type input: " < NUL
set "INPUT="
rem Get two *UPPERCASE* letters
set "letter= ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for /L %%i in (1,1,2) do (
choice /C %letter% /N > NUL
for %%l in ("!errorlevel!") do set "INPUT=!INPUT!!letter:~%%~l,1!"
set /P "=!INPUT:~-1!" < NUL
)
rem Get eight digits
set "digit= 0123456789"
for /L %%i in (1,1,8) do (
choice /C %digit% /N > NUL
for %%l in ("!errorlevel!") do set "INPUT=!INPUT!!digit:~%%~l,1!"
set /P "=!INPUT:~-1!" < NUL
)
echo/
echo INPUT = "%INPUT%"
In this code:
Any letter pressed is converted to uppercase. This behavior may be cancelled including both upcase and lowcase letters in letter variable and adding /CS switch to choice command.
The last character input can not be deleted.
The input is automatically completed after the last character is input. No final ENTER key is needed.
If you want not this behavior and need more precise control on the input characters, then you must use another method; for example, reading the keys via xcopy trick. The link posted by Squashman above is an ample example on how to do that...
Aacini's answer also forces valid user input vs validating retroactilvey, his answer is less code and more "readable" IMO. I will be using his answer, but I figured I'd share this method.
I asked to "retroactively" validate user input, but #Squashmans commented URL forces valid user input in the first place.
https://www.dostips.com/forum/viewtopic.php?t=5775
Here is the "sanitized code" that I ended up with.
#echo off
#cls
::::START -- Section Blocks User from Inputting Invalid Data::::
setlocal
set "thisFile=%~F0"
call :ReadFormattedLine INPUT="__########" /M "Enter Input in Form XY########: "
echo/
:ReadFormattedLine var="mask" [/M "message"] [/P] [/F /W /A]
if "%~2" equ "" echo ERROR: Missing parameters & exit /B 1
setlocal EnableDelayedExpansion
set "var=%~1"
set "mask=%~2"
shift & shift
set "message="
if /I "%1" equ "/M" set "message=%~2" & shift & shift
set "password="
if /I "%1" equ "/P" set "password=1" & shift
set "switch=%~1"
set quote="
set "digit= 0 1 2 3 4 5 6 7 8 9 "
set "letter= A B C D E F G H I J K L M N O P Q R S T U V W X Y Z "
set "alphaNum=%digit%%letter%"
set "fmt=#_+?#"
set "show=$/\()[]:;,.- %digit: =%%letter: =%"
for /F %%a in ('copy /Z "%thisFile%" NUL') do set "CR=%%a"
for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a" & set "SP=.%%a "
< NUL (
set /P "=%message%"
for /F "eol=| delims=" %%a in ('cmd /U /C echo !mask!^| find /V ""') do (
if "!fmt:%%a=!" neq "%fmt%" (
set /P "=Û"
) else if "%%a" neq " " (
set /P "=%%a"
) else (
set /P "=!SP!"
)
)
set /P "=!SP!!CR!%message%"
)
set "input="
set /A i=0, key=0
goto checkFormat
:nextKey
set "key="
for /F "delims=" %%a in ('xcopy /W "%thisFile%" "%thisFile%" 2^>NUL') do if not defined key set "key=%%a"
if "!key:~-1!" neq "!CR!" goto endif
if /I "%switch%" equ "/A" goto nextKey
if /I "%switch%" neq "/F" goto check/W
:nextField
set "format=!mask:~%i%,1!"
if "%format%" equ "" goto endRead
if "!fmt:%format%=!" equ "%fmt%" goto checkFormat
set /P "=Û" < NUL
set "input=%input% "
set /A i+=1
goto nextField
:check/W
if /I "%switch%" neq "/W" goto checkEmpty
if %i% equ 0 goto endRead
if "%format%" equ "" goto endRead
goto nextKey
:checkEmpty
if %i% gtr 0 goto endRead
goto nextKey
:endif
set "key=!key:~-1!"
if "!key!" equ "!BS!" (
if %i% gtr 0 (
if "%format%" equ "" (
set /P "=!SP!!BS!!BS!Û!BS!" < NUL
) else (
set /P "=Û!BS!!BS!Û!BS!" < NUL
)
set "input=%input:~0,-1%"
set /A i-=1
if !i! equ 0 set key=0
)
goto checkFormat
)
if "%format%" equ "" goto nextKey
if "!key!" equ "=" goto nextKey
if "!key!" equ "!quote!" goto nextKey
if "%format%" equ "#" ( rem Any digit
if "!digit: %key% =!" equ "%digit%" goto nextKey
) else if "%format%" equ "_" ( rem Any letter
if "!letter: %key% =!" equ "%letter%" goto nextKey
) else if "%format%" equ "+" ( rem Any letter, convert it to uppercase
if "!letter: %key% =!" equ "%letter%" goto nextKey
for %%a in (%letter%) do if /I "!key!" equ "%%a" set "key=%%a"
) else (
rem Rest of formats are alphanumeric: ? #
if "!alphaNum: %key% =!" equ "%alphaNum%" goto nextKey
if "%format%" equ "#" ( rem Convert letters to uppercase
for %%a in (%letter%) do if /I "!key!" equ "%%a" set "key=%%a"
) else if "%format%" neq "?" echo ERROR: Invalid format in mask: "%format%" & exit /B 2
)
)
if defined password (
set /P "=*" < NUL
) else (
set /P "=%key%" < NUL
)
set "input=%input%%key%"
:nextFormat
set /A i+=1
:checkFormat
set "format=!mask:~%i%,1!"
if "%format%" equ "" (
if /I "%switch%" equ "/A" goto endRead
if /I "%switch%" equ "/M" goto endRead
goto nextKey
)
if "!show:%format%=!" neq "%show%" (
if "!key!" equ "!BS!" (
if "%format%" neq " " (
set /P "=%format%!BS!!BS!Û!BS!" < NUL
) else (
set /P "=!SP!!BS!!BS!Û!BS!" < NUL
)
set "input=%input:~0,-1%"
set /A i-=1
if !i! equ 0 set key=0
goto checkFormat
) else (
if "%format%" neq " " (
set /P "=%format%" < NUL
) else (
set /P "=!SP!" < NUL
)
set "input=%input%%format%"
goto nextFormat
)
)
if "%input:~-1%!key!" equ " !BS!" (
set /P "=Û!BS!!BS!" < NUL
set "input=%input:~0,-1%"
set /A i-=1
goto checkFormat
)
goto nextKey
:endRead
echo/
endlocal & set "%var%=%input%"
echo %INPUT%
pause
exit /B

how to run cmd command netsh using notepad

I want to make autorun .bat program that automatically performs netsh cmd and save the result in .txt file by the just simple click of a button.
below is what I wrote in notepad and saved as getkey.bat
echo netsh wlan show profile name=wifi_name key=clear >Desktop/savedpasskey.txt
exit
but it is not working
To show the password of your WIFI SSID , you must execute this batch file with admin rights :
#echo off & setlocal enabledelayedexpansion
Set "Copyright=by Hackoo 2017"
Title %~n0 %Copyright%
Mode con cols=75 lines=8
cls & color 0A & echo.
echo ***********************************************
echo %~n0 %Copyright%
echo ***********************************************
echo(
if _%1_==_Main_ goto :Main
Set Count=0
Set L=0
:getadmin
echo %~nx0 : self elevating
set vbs=%temp%\getadmin.vbs
(
echo Set UAC = CreateObject^("Shell.Application"^)
echo UAC.ShellExecute "%~s0", "Main %~sdp0 %*", "", "runas", 1
)> "%vbs%"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
goto :eof
::*************************************************************************************
:Main
Call :init
Call :CountLines
Set "PasswordLog=%~dp0Wifi_Passwords_on_%ComputerName%.txt"
%Mod%
echo(
echo ***********************************************
echo %~n0 %Copyright%
echo ***********************************************
echo(
Call :Color 0E " [N][SSID] ================ Password" 1
echo(
(
echo ***********************************************
echo %~n0 %Copyright%
echo ***********************************************
echo(
echo [N][SSID] ==============^> "Password"
echo(
)>"%PasswordLog%"
for /f "skip=2 delims=: tokens=2" %%a in ('netsh wlan show profiles') do (
if not "%%a"=="" (
set "ssid=%%a"
set "ssid=!ssid:~1!"
call :Getpassword "!ssid!"
)
)
echo(
echo Done
If exist "%PasswordLog%" start "" "%PasswordLog%"
pause>nul
exit
::*************************************************************************************
:Getpassword
set "name=%1"
set "name=!name:"=!"
Set "passwd="
for /f "delims=: tokens=2" %%a in ('netsh wlan show profiles %1 key^=clear ^|find /I "Cont"') do (
set "passwd=%%a"
Set /a Count+=1
)
If defined passwd (
set passwd=!passwd:~1!
echo [!Count!][!name!] ====^> "!passwd!"
echo [!Count!][!name!] ====^> "!passwd!" >> "%PasswordLog%"
) else (
Set /a Count+=1
call :color 0C " [!Count!][!name!] The Password is empty" 1
echo [!Count!][!name!] The Password is empty >> "%PasswordLog%"
)
exit /b
::*************************************************************************************
:init
prompt $g
for /F "delims=." %%a in ('"prompt $H. & for %%b in (1) do rem"') do set "BS=%%a"
exit /b
::*************************************************************************************
:color
set nL=%3
if not defined nL echo requires third argument & pause > nul & goto :eof
if %3 == 0 (
<nul set /p ".=%bs%">%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
) else if %3 == 1 (
echo %bs%>%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
)
exit /b
::*************************************************************************************
:CountLines
for /f "skip=2 delims=: tokens=2" %%a in ('netsh wlan show profiles') do (
if not "%%a"=="" (
set /a L+=1
)
)
set /a L=!L! + 10
Set Mod=Mode con cols=75 Lines=!L!
exit /b
::*************************************************************************************
This works. You can change the TEMPFILE to wherever you want the file to be created.
SET "TEMPFILE=%USERPROFILE%\Desktop\savedpasskey.txt"
netsh wlan show profile name=wifi_name key=clear >"%TEMPFILE%"
TYPE "%TEMPFILE%"
It was not working because the path you specified to save your output text file was not getting recognized. The below code should work properly.
#echo off
netsh wlan show profile name=wifi_name key=clear >%USERPROFILE%\Desktop\savedpasskey.txt
#pause
It's always better to specify fully qualified path for the files. In this case it will be C:\Users\<User_Name>\Desktop\savedpasskey.txt where %USERPROFILE% will been replaced with C:\Users\<User_Name>.
Remove #pause if you don't want the command prompt to stay on screen after command is executed.

multiple windows to 1 single window batch

I have 2 batch files I want to merge from 2 screens to 1 screen.
currently there is 2 screens:
1 screen is the chat room
1 screen is the message input screen.
I want to merge these into 1 batch file on the screen so it requests users input on the chat room screen
is that possible?
My code I want to merge is here:
----------------------------
chat.bat
----------------------------
#echo off
:StartUp
set rr=2
mode con cols=40 lines=8
if exist tmp.bat del /f /s /q tmp.bat
set hd=%cd%
title Remote Chat
color 0f
cls
echo [Remote Chat]
echo.
echo Made by Jordan Begg
echo 31/12/2013
set t1=%time:~6,2%
set /a t2=%t1%+2
if %t2% geq 60 set /a t2=%t2% - 59
:ExpLoop
if %time:~6,2% geq %t2% goto Go
goto ExpLoop
:Go
set cs=ChatSettings.bat
if exist %cs% (
call %cs%
goto Main
) else (
goto SetUp
)
:SetUp
cls
mkdir "C:\chat"
echo [Setup]
echo.
set /p un=Username:
if not defined un goto SetUp
:SetUp2
cls
echo [Setup]
echo.
echo Use this:
echo C:\chat
if defined sd echo Current: %sd%
echo.
set /p sd=Server folder:
if not defined sd goto SetUp2
set sd=%sd%
if not exist %sd% (
set sd=
echo Folder doesn't exist!
pause >nul
goto SetUp2
)
if exist %cs% del /f /s /q %cs%
echo set un=%un%>>%cs%
echo set sd=%sd%>>%cs%
echo set rr=4>>%cs%
goto Main
:Main
cd %hd%
cls
echo [Remote Chat]
echo.
echo 1 - Join
echo 2 - Create
echo 4 - Exit
echo.
set /p c=
if %c%==1 goto Join
if %c%==2 goto create1
if %c%==4 goto Exit
goto main
:Exit
exit
:create1
cls
echo Please enter a valid asset ID (i.e as0123456)
set /p ass=Asset:
ping -n 1 %ass% > c:\ping.tmp
type c:\ping.tmp | FIND "Approximate round trip" >NUL
IF ERRORLEVEL 1 GOTO NOPING
goto Create
:noping
echo Asset cannot be reached
echo.
goto create1
:Create
cd %sd%
set rn=
cls
echo [Create]
echo.
echo created
echo.
set rn=%ass%
echo %rn%
pause
if not defined rn goto Create
set rf=%sd%\%rn%.crm
if exist %rf% goto Create
cls
echo [Create]
echo.
echo Preparing room, please wait.
set group=Admin
echo [%time:~0,5%] %un% (admin) connected.>>%rf%
title Chat [%rn%]
cd %hd%
echo set rn=%rn%>>tmp.bat
echo set rf=%rf%>>tmp.bat
echo set group=%group%>>tmp.bat
start ChatMessage.bat
start ChatDisconnect.bat
cd %sd%
mode con cols=40 lines=16
:Admin
cls
cd %hd% >nul
if not exist tmp.bat (
set msg=Room closed successfully.
goto End
)
cd %sd% >nul
if not exist %rf% (
set msg=Connection terminated.
goto End
)
type %rf%
ping localhost -n 4 >nul
goto Admin
set t=%time:~7,1%+%rr%
if %t% GEQ 10 set /a t=%t% - 10
:AdminL
if %time:~7,1%==%t% goto Admin
:End
if exist tmp.bat del /f /s /q tmp.bat
mode con cols=40 lines=8
echo [Chat]
echo.
echo %msg%
set msg=
taskkill /f /fi "WINDOWTITLE eq Message" >nul
taskkill /f /fi "WINDOWTITLE eq Disconnect" >nul
title Chat
set group=
set rn=
set t1=%time:~6,2%
set /a t2=%t1%+2
if %t2% geq 60 set /a t2=%t2% - 5
:EndLoop
if %time:~6,2% geq %t2% goto Main
goto EndLoop
:Join
mode con cols=40 lines=16
cd %sd%
set rn=
cls
echo [Join]
echo.
if not exist %sd%\*crm (
echo No rooms available.
pause >nul
mode con cols=40 lines=8
goto Main
)
dir /b /o:n %sd%\*.crm
echo.
echo Format (no .crm at end): Room
set /p rn=Room's name:
if not defined rn goto Join
set rf=%sd%\%rn%.crm
if not exist %rf% goto Join
cls
echo [Join]
echo.
echo Joining room, please wait.
set group=User
echo [%time:~0,5%] %un% connected.>>%rf%
title Chat [%rn%]
cd %hd%
echo set rn=%rn%>>tmp.bat
echo set rf=%rf%>>tmp.bat
echo set group=%group%>>tmp.bat
start ChatMessage.bat
start ChatDisconnect.bat
cd %sd%
:User
cls
cd %hd% >nul
if not exist tmp.bat (
set msg=Disconnected successfully.
goto End
)
cd %sd% >nul
if not exist %rf% (
set msg=Connection terminated.
goto End
)
type %rf%
ping localhost -n 4 >nul
goto User
.
-----------------------
chatmessage.bat
------------------------
#echo off
if not exist tmp.bat (
exit
) else (
call tmp.bat
call ChatSettings.bat
)
title Message
mode con cols=30 lines=2
cd %sd%
:func
cls
set /p msg=Message:
if %msg:~0,3%==/me echo [%time:~0,5%] %un% %msg:~4%>>%rf%&& goto func
if not defined msg goto func
echo [%time:~0,5%] %un%: %msg%>>%rf%
goto func

Resources