Files
HyperCLI/files/experimental/software-management-tool.bat
2026-02-04 09:36:55 +01:00

816 lines
20 KiB
Batchfile

@echo off
REM === Software Management Tool ===
chcp 65001 >nul
setlocal enabledelayedexpansion
:MENU
cls
echo ========================================
echo Software Management Tool
echo ========================================
echo.
set /p ENABLE_EXPORT="Enable auto-export of reports? (Y/N): "
echo.
echo ========================================
echo.
echo [1] Scan installed software
echo [2] Check for updates
echo [3] Uninstall software
echo [4] Full system report
echo [0] Exit
echo.
echo ========================================
set /p CHOICE="Select option: "
if "%CHOICE%"=="1" goto SCAN_SOFTWARE
if "%CHOICE%"=="2" goto CHECK_UPDATES
if "%CHOICE%"=="3" goto UNINSTALL_SOFTWARE
if "%CHOICE%"=="4" goto FULL_REPORT
if "%CHOICE%"=="0" goto EXIT
goto MENU
:SCAN_SOFTWARE
cls
echo ========================================
echo Scan Installed Software
echo ========================================
echo.
echo Scanning system registry...
echo.
set "tempfile=%TEMP%\software_scan_%RANDOM%.tmp"
(
echo ========================================
echo INSTALLED SOFTWARE SCAN
echo Date: %date% %time%
echo Computer: %COMPUTERNAME%
echo ========================================
echo.
) > "%tempfile%"
REM 64-Bit Software
echo [1/3] Scanning 64-bit programs...
(
echo [64-BIT PROGRAMS]
echo ----------------------------------------
) >> "%tempfile%"
set COUNT64=0
for /f "tokens=*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 2^>nul') do (
set "hasname="
set "hasver="
for /f "skip=2 tokens=2*" %%b in ('reg query "%%a" /v DisplayName 2^>nul') do set "hasname=%%c"
for /f "skip=2 tokens=2*" %%b in ('reg query "%%a" /v DisplayVersion 2^>nul') do set "hasver=%%c"
if defined hasname (
set /a COUNT64+=1
if defined hasver (
echo !hasname! [!hasver!] >> "%tempfile%"
) else (
echo !hasname! >> "%tempfile%"
)
)
)
echo Total: !COUNT64! programs >> "%tempfile%"
echo. >> "%tempfile%"
REM 32-Bit Software
echo [2/3] Scanning 32-bit programs...
(
echo [32-BIT PROGRAMS]
echo ----------------------------------------
) >> "%tempfile%"
set COUNT32=0
for /f "tokens=*" %%a in ('reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" 2^>nul') do (
set "hasname="
set "hasver="
for /f "skip=2 tokens=2*" %%b in ('reg query "%%a" /v DisplayName 2^>nul') do set "hasname=%%c"
for /f "skip=2 tokens=2*" %%b in ('reg query "%%a" /v DisplayVersion 2^>nul') do set "hasver=%%c"
if defined hasname (
set /a COUNT32+=1
if defined hasver (
echo !hasname! [!hasver!] >> "%tempfile%"
) else (
echo !hasname! >> "%tempfile%"
)
)
)
echo Total: !COUNT32! programs >> "%tempfile%"
echo. >> "%tempfile%"
REM User Software
echo [3/3] Scanning user-installed programs...
(
echo [USER PROGRAMS]
echo ----------------------------------------
) >> "%tempfile%"
set COUNTUSER=0
for /f "tokens=*" %%a in ('reg query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 2^>nul') do (
set "hasname="
set "hasver="
for /f "skip=2 tokens=2*" %%b in ('reg query "%%a" /v DisplayName 2^>nul') do set "hasname=%%c"
for /f "skip=2 tokens=2*" %%b in ('reg query "%%a" /v DisplayVersion 2^>nul') do set "hasver=%%c"
if defined hasname (
set /a COUNTUSER+=1
if defined hasver (
echo !hasname! [!hasver!] >> "%tempfile%"
) else (
echo !hasname! >> "%tempfile%"
)
)
)
echo Total: !COUNTUSER! programs >> "%tempfile%"
echo. >> "%tempfile%"
set /a TOTAL=COUNT64+COUNT32+COUNTUSER
(
echo ========================================
echo SUMMARY
echo ========================================
echo 64-bit programs: !COUNT64!
echo 32-bit programs: !COUNT32!
echo User programs: !COUNTUSER!
echo ----------------------------------------
echo Total installed: !TOTAL!
echo ========================================
) >> "%tempfile%"
cls
type "%tempfile%"
echo.
if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%tempfile%" "Software_Scan"
del "%tempfile%" >nul 2>&1
pause
goto MENU
:CHECK_UPDATES
cls
echo ========================================
echo Check for Updates
echo ========================================
echo.
set "tempfile=%TEMP%\update_check_%RANDOM%.tmp"
set "updatelist=%TEMP%\update_programs_%RANDOM%.tmp"
(
echo ========================================
echo UPDATE CHECK REPORT
echo Date: %date% %time%
echo Computer: %COMPUTERNAME%
echo ========================================
echo.
) > "%tempfile%"
echo Checking for available updates...
echo.
REM Check if winget is available
where winget >nul 2>&1
if %errorlevel%==0 (
echo Using Windows Package Manager (winget)...
echo. >> "%tempfile%"
echo [AVAILABLE UPDATES] >> "%tempfile%"
echo ---------------------------------------- >> "%tempfile%"
REM Get list of upgradeable packages
winget upgrade > "%updatelist%" 2>&1
type "%updatelist%" >> "%tempfile%"
echo. >> "%tempfile%"
echo ======================================== >> "%tempfile%"
) else (
echo [NOTE] Winget is not installed. >> "%tempfile%"
echo Cannot check for updates automatically. >> "%tempfile%"
echo. >> "%tempfile%"
echo Please install Windows Package Manager or check manually. >> "%tempfile%"
echo ======================================== >> "%tempfile%"
cls
type "%tempfile%"
echo.
if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%tempfile%" "Update_Check"
del "%tempfile%" >nul 2>&1
del "%updatelist%" >nul 2>&1
pause
goto MENU
)
cls
type "%tempfile%"
echo.
REM Check if updates are available
findstr /C:"upgrades available" "%updatelist%" >nul 2>&1
if %errorlevel%==0 (
echo No updates available.
if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%tempfile%" "Update_Check"
del "%tempfile%" >nul 2>&1
del "%updatelist%" >nul 2>&1
pause
goto MENU
)
echo ========================================
set /p INSTALL_CHOICE="Install updates? (Y/N): "
if /i not "%INSTALL_CHOICE%"=="Y" (
if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%tempfile%" "Update_Check"
del "%tempfile%" >nul 2>&1
del "%updatelist%" >nul 2>&1
pause
goto MENU
)
cls
echo ========================================
echo Install Updates
echo ========================================
echo.
echo [1] Update all programs
echo [2] Select specific programs
echo [0] Cancel
echo.
set /p UPDATE_METHOD="Select option: "
if "%UPDATE_METHOD%"=="1" (
del "%tempfile%" >nul 2>&1
del "%updatelist%" >nul 2>&1
goto UPDATE_ALL_PROGRAMS
)
if "%UPDATE_METHOD%"=="2" (
goto SELECT_UPDATES
)
if "%UPDATE_METHOD%"=="0" (
if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%tempfile%" "Update_Check"
del "%tempfile%" >nul 2>&1
del "%updatelist%" >nul 2>&1
pause
goto MENU
)
del "%tempfile%" >nul 2>&1
del "%updatelist%" >nul 2>&1
goto CHECK_UPDATES
:SELECT_UPDATES
cls
echo ========================================
echo Select Programs to Update
echo ========================================
echo.
echo Extracting available updates...
echo.
set "pkglist=%TEMP%\packages_%RANDOM%.tmp"
REM Extract package IDs from winget output
winget upgrade | findstr /V /C:"Name" /C:"---" /C:"upgrades available" | findstr /V "^$" > "%pkglist%" 2>nul
REM Count available packages
set PKG_COUNT=0
for /f "tokens=*" %%a in ('type "%pkglist%"') do set /a PKG_COUNT+=1
if %PKG_COUNT%==0 (
echo No updatable packages found.
del "%pkglist%" >nul 2>&1
del "%tempfile%" >nul 2>&1
del "%updatelist%" >nul 2>&1
pause
goto MENU
)
REM Display packages with numbers
cls
echo ========================================
echo Available Updates
echo ========================================
echo.
echo Enter the numbers of programs to update (separated by spaces)
echo Example: 1 3 5 7
echo.
echo ----------------------------------------
set INDEX=0
for /f "tokens=1* delims= " %%a in ('type "%pkglist%"') do (
set /a INDEX+=1
set "PKG_!INDEX!=%%a"
echo [!INDEX!] %%a
)
echo ----------------------------------------
echo.
set /p SELECTIONS="Enter numbers (space-separated): "
if "%SELECTIONS%"=="" (
echo [ERROR] No selection made!
del "%pkglist%" >nul 2>&1
del "%tempfile%" >nul 2>&1
del "%updatelist%" >nul 2>&1
pause
goto MENU
)
cls
echo ========================================
echo Installing Selected Updates
echo ========================================
echo.
set "logfile=%TEMP%\update_selected_%RANDOM%.log"
(
echo ========================================
echo SELECTED UPDATES INSTALLATION LOG
echo Date: %date% %time%
echo ========================================
echo.
) > "%logfile%"
REM Process selections
for %%S in (%SELECTIONS%) do (
if defined PKG_%%S (
echo ---------------------------------------- >> "%logfile%"
echo Updating: !PKG_%%S! >> "%logfile%"
echo ---------------------------------------- >> "%logfile%"
echo Updating: !PKG_%%S!
winget upgrade --id "!PKG_%%S!" --accept-source-agreements --accept-package-agreements >> "%logfile%" 2>&1
echo. >> "%logfile%"
)
)
echo ======================================== >> "%logfile%"
echo Update process completed. >> "%logfile%"
cls
type "%logfile%"
echo.
if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%logfile%" "Update_Selected"
del "%logfile%" >nul 2>&1
del "%pkglist%" >nul 2>&1
del "%tempfile%" >nul 2>&1
del "%updatelist%" >nul 2>&1
pause
goto MENU
:UPDATE_ALL_PROGRAMS
cls
echo ========================================
echo Update All Programs
echo ========================================
echo.
echo Updating all available programs...
echo.
set "logfile=%TEMP%\update_all_%RANDOM%.log"
(
echo ========================================
echo UPDATE ALL PROGRAMS LOG
echo Date: %date% %time%
echo ========================================
echo.
) > "%logfile%"
where winget >nul 2>&1
if %errorlevel%==0 (
echo Starting update process... >> "%logfile%"
echo. >> "%logfile%"
winget upgrade --all --accept-source-agreements --accept-package-agreements >> "%logfile%" 2>&1
echo. >> "%logfile%"
echo Update process completed. >> "%logfile%"
) else (
echo [ERROR] Winget is not installed! >> "%logfile%"
echo Cannot update programs automatically. >> "%logfile%"
)
echo ======================================== >> "%logfile%"
cls
type "%logfile%"
echo.
if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%logfile%" "Update_All"
del "%logfile%" >nul 2>&1
pause
goto MENU
:UNINSTALL_SOFTWARE
cls
echo ========================================
echo Uninstall Software
echo ========================================
echo.
echo [1] View installed programs
echo [2] Uninstall by name
echo [3] Select programs to uninstall (interactive)
echo [0] Back to menu
echo.
set /p UNINSTALL_CHOICE="Select option: "
if "%UNINSTALL_CHOICE%"=="1" goto VIEW_FOR_UNINSTALL
if "%UNINSTALL_CHOICE%"=="2" goto UNINSTALL_BY_NAME
if "%UNINSTALL_CHOICE%"=="3" goto SELECT_UNINSTALL
if "%UNINSTALL_CHOICE%"=="0" goto MENU
goto UNINSTALL_SOFTWARE
:VIEW_FOR_UNINSTALL
cls
echo ========================================
echo Installed Programs
echo ========================================
echo.
echo Scanning...
echo.
set "tempfile=%TEMP%\uninstall_list_%RANDOM%.tmp"
(
echo Available Programs:
echo ========================================
echo.
) > "%tempfile%"
set COUNT=0
for /f "tokens=*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 2^>nul') do (
for /f "skip=2 tokens=2*" %%b in ('reg query "%%a" /v DisplayName 2^>nul') do (
set /a COUNT+=1
echo !COUNT!. %%c >> "%tempfile%"
)
)
for /f "tokens=*" %%a in ('reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" 2^>nul') do (
for /f "skip=2 tokens=2*" %%b in ('reg query "%%a" /v DisplayName 2^>nul') do (
set /a COUNT+=1
echo !COUNT!. %%c >> "%tempfile%"
)
)
cls
type "%tempfile%"
echo.
echo ========================================
del "%tempfile%" >nul 2>&1
pause
goto UNINSTALL_SOFTWARE
:SELECT_UNINSTALL
cls
echo ========================================
echo Select Programs to Uninstall
echo ========================================
echo.
echo Scanning installed programs...
echo.
REM Collect all programs directly into arrays
set INDEX=0
set "templist=%TEMP%\prog_temp_%RANDOM%.txt"
echo Collecting 64-bit programs...
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 2>nul > "%templist%"
for /f "tokens=*" %%a in ('type "%templist%"') do (
reg query "%%a" /v DisplayName 2>nul | findstr "DisplayName" >nul
if !errorlevel!==0 (
for /f "skip=2 tokens=2*" %%b in ('reg query "%%a" /v DisplayName 2^>nul') do (
set /a INDEX+=1
set "PROG_NAME_!INDEX!=%%c"
set "PROG_REG_!INDEX!=%%a"
set "SELECTED_!INDEX!=0"
)
)
)
echo Collecting 32-bit programs...
reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" 2>nul > "%templist%"
for /f "tokens=*" %%a in ('type "%templist%"') do (
reg query "%%a" /v DisplayName 2>nul | findstr "DisplayName" >nul
if !errorlevel!==0 (
for /f "skip=2 tokens=2*" %%b in ('reg query "%%a" /v DisplayName 2^>nul') do (
set /a INDEX+=1
set "PROG_NAME_!INDEX!=%%c"
set "PROG_REG_!INDEX!=%%a"
set "SELECTED_!INDEX!=0"
)
)
)
echo Collecting user programs...
reg query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 2>nul > "%templist%"
for /f "tokens=*" %%a in ('type "%templist%"') do (
reg query "%%a" /v DisplayName 2>nul | findstr "DisplayName" >nul
if !errorlevel!==0 (
for /f "skip=2 tokens=2*" %%b in ('reg query "%%a" /v DisplayName 2^>nul') do (
set /a INDEX+=1
set "PROG_NAME_!INDEX!=%%c (User)"
set "PROG_REG_!INDEX!=%%a"
set "SELECTED_!INDEX!=0"
)
)
)
del "%templist%" >nul 2>&1
echo.
echo Found !INDEX! programs total.
if %INDEX%==0 (
echo No programs found!
pause
goto UNINSTALL_SOFTWARE
)
set CURRENT=1
set TOTAL=%INDEX%
:DISPLAY_SELECTION
cls
echo ========================================
echo Select Programs to Uninstall
echo ========================================
echo.
echo Enter the numbers of programs to uninstall (separated by spaces)
echo Example: 1 3 5 7
echo Or press 0 to cancel
echo.
echo ----------------------------------------
echo.
REM Display all programs with numbers
for /l %%i in (1,1,%TOTAL%) do (
echo [%%i] !PROG_NAME_%%i!
)
echo.
echo ----------------------------------------
set /p SELECTIONS="Enter numbers (space-separated) or 0 to cancel: "
if "%SELECTIONS%"=="0" goto CANCEL_SELECTION
if "%SELECTIONS%"=="" goto DISPLAY_SELECTION
REM Mark selected programs
for %%S in (%SELECTIONS%) do (
if defined PROG_NAME_%%S (
set "SELECTED_%%S=1"
)
)
goto CONFIRM_SELECTION
:CANCEL_SELECTION
goto UNINSTALL_SOFTWARE
:CONFIRM_SELECTION
REM Check if any programs selected
set SELECTED_COUNT=0
for /l %%i in (1,1,%TOTAL%) do (
if !SELECTED_%%i!==1 set /a SELECTED_COUNT+=1
)
if %SELECTED_COUNT%==0 (
echo.
echo [WARNING] No valid programs selected!
timeout /t 2 >nul
goto CANCEL_SELECTION
)
cls
echo ========================================
echo Confirm Uninstallation
echo ========================================
echo.
echo The following programs will be uninstalled:
echo.
for /l %%i in (1,1,%TOTAL%) do (
if !SELECTED_%%i!==1 (
echo - !PROG_NAME_%%i!
)
)
echo.
echo ========================================
set /p CONFIRM="Are you sure? (Y/N): "
if /i not "%CONFIRM%"=="Y" goto CANCEL_SELECTION
cls
echo ========================================
echo Uninstalling Selected Programs
echo ========================================
echo.
set "logfile=%TEMP%\\uninstall_log_%RANDOM%.log"
(
echo ========================================
echo UNINSTALL LOG
echo Date: %date% %time%
echo ========================================
echo.
) > "%logfile%"
REM Uninstall selected programs
for /l %%i in (1,1,%TOTAL%) do (
if !SELECTED_%%i!==1 (
echo ---------------------------------------- >> "%logfile%"
echo Uninstalling: !PROG_NAME_%%i! >> "%logfile%"
echo Registry: !PROG_REG_%%i! >> "%logfile%"
echo ---------------------------------------- >> "%logfile%"
echo Uninstalling: !PROG_NAME_%%i!
REM Try to get uninstall string
for /f "skip=2 tokens=2*" %%u in ('reg query "!PROG_REG_%%i!" /v UninstallString 2^>nul') do (
echo Uninstall command: %%v >> "%logfile%"
REM Execute uninstall
echo Running uninstaller... >> "%logfile%"
start /wait "" %%v >> "%logfile%" 2>&1
if !errorlevel!==0 (
echo [SUCCESS] Uninstalled successfully >> "%logfile%"
echo [SUCCESS] Uninstalled successfully
) else (
echo [WARNING] Uninstall may have failed or was cancelled >> "%logfile%"
echo [WARNING] Uninstall may have failed or was cancelled
)
)
echo. >> "%logfile%"
)
)
echo ======================================== >> "%logfile%"
echo Uninstall process completed. >> "%logfile%"
cls
type "%logfile%"
echo.
if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%logfile%" "Uninstall_Selected"
del "%logfile%" >nul 2>&1
pause
goto MENU
:UNINSTALL_BY_NAME
cls
echo ========================================
echo Uninstall by Name
echo ========================================
echo.
set /p PROGRAM_NAME="Enter program name: "
if "%PROGRAM_NAME%"=="" (
echo [ERROR] No program name entered!
pause
goto UNINSTALL_SOFTWARE
)
echo.
echo Searching for: %PROGRAM_NAME%
echo.
where winget >nul 2>&1
if %errorlevel%==0 (
winget uninstall "%PROGRAM_NAME%"
) else (
echo [NOTE] Using Windows Settings...
start ms-settings:appsfeatures
)
pause
goto MENU
:FULL_REPORT
cls
echo ========================================
echo Full System Report
echo ========================================
echo.
set "tempfile=%TEMP%\full_report_%RANDOM%.tmp"
(
echo ========================================
echo FULL SYSTEM REPORT
echo Date: %date% %time%
echo Computer: %COMPUTERNAME%
echo User: %USERNAME%
echo ========================================
echo.
) > "%tempfile%"
echo [1/4] System Information...
(
echo [SYSTEM INFORMATION]
echo ----------------------------------------
) >> "%tempfile%"
systeminfo | findstr /C:"OS Name" /C:"OS Version" /C:"System Type" /C:"Total Physical Memory" >> "%tempfile%"
echo. >> "%tempfile%"
echo [2/4] Installed Software...
(
echo [INSTALLED SOFTWARE]
echo ----------------------------------------
) >> "%tempfile%"
set TOTALSOFT=0
for /f "tokens=*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" 2^>nul') do (
for /f "skip=2 tokens=2*" %%b in ('reg query "%%a" /v DisplayName 2^>nul') do (
set /a TOTALSOFT+=1
echo %%c >> "%tempfile%"
)
)
for /f "tokens=*" %%a in ('reg query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" 2^>nul') do (
for /f "skip=2 tokens=2*" %%b in ('reg query "%%a" /v DisplayName 2^>nul') do (
set /a TOTALSOFT+=1
echo %%c >> "%tempfile%"
)
)
echo. >> "%tempfile%"
echo Total: !TOTALSOFT! programs >> "%tempfile%"
echo. >> "%tempfile%"
echo [3/4] Running Processes...
(
echo [RUNNING PROCESSES]
echo ----------------------------------------
) >> "%tempfile%"
tasklist >> "%tempfile%"
echo. >> "%tempfile%"
echo [4/4] Available Updates...
(
echo [AVAILABLE UPDATES]
echo ----------------------------------------
) >> "%tempfile%"
where winget >nul 2>&1
if %errorlevel%==0 (
winget upgrade >> "%tempfile%" 2>&1
) else (
echo [NOTE] Winget is not installed. >> "%tempfile%"
echo Cannot check for updates. >> "%tempfile%"
)
echo ======================================== >> "%tempfile%"
cls
type "%tempfile%"
echo.
if /i "%ENABLE_EXPORT%"=="Y" call :EXPORT_FILE "%tempfile%" "Full_System_Report"
del "%tempfile%" >nul 2>&1
pause
goto MENU
:EXPORT_FILE
set "source=%~1"
set "basename=%~2"
set "exportfile=%USERPROFILE%\Desktop\%basename%_%date:~-4,4%%date:~-7,2%%date:~-10,2%_%time:~0,2%%time:~3,2%%time:~6,2%.txt"
set "exportfile=%exportfile: =0%"
copy "%source%" "%exportfile%" >nul 2>&1
if %errorlevel%==0 (
echo.
echo [SUCCESS] Report exported to:
echo %exportfile%
echo.
) else (
echo.
echo [ERROR] Could not export file!
echo.
)
exit /b
:EXIT
cls
echo ========================================
echo Thank you for using Software Management Tool
echo ========================================
echo.
timeout /t 2 >nul
exit