243 lines
10 KiB
Batchfile
243 lines
10 KiB
Batchfile
@echo off
|
|
setlocal EnableDelayedExpansion
|
|
|
|
:: ============================================================================
|
|
:: CONFIGURATION (SYNCED WITH INSTALL.BAT)
|
|
:: ============================================================================
|
|
set "SCRIPT_DIR=%~dp0"
|
|
for %%I in ("%SCRIPT_DIR%..") do (
|
|
set "ROOT_DIR=%%~fI\"
|
|
set "ROOT_FOLDER_NAME=%%~nxI"
|
|
)
|
|
set "CLEAN_ROOT=%ROOT_DIR:~0,-1%"
|
|
|
|
set "WSL_DISTRO=Ubuntu-22.04"
|
|
set "PROJECT_NAME=walmart"
|
|
set "PROJECT_DIR=/opt/walmart"
|
|
set "KIOSK_APP_DIR=C:\KioskApp"
|
|
set "KIOSK_DATA_DIR=C:\KioskBrowserData"
|
|
|
|
:: ============================================================================
|
|
:: 0. AUTO-ELEVATE TO ADMINISTRATOR
|
|
:: ============================================================================
|
|
net session >nul 2>&1
|
|
if %errorLevel% neq 0 (
|
|
echo Requesting Administrator privileges...
|
|
powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
|
|
exit /b
|
|
)
|
|
|
|
echo ============================================================================
|
|
echo DTS TORQUE VAULT - KIOSK MODE UNINSTALLER AND SYSTEM RESTORE
|
|
echo ============================================================================
|
|
echo.
|
|
echo Select uninstall mode:
|
|
echo [1] Auto Wipe All - Automatically remove Kiosk user, browser data,
|
|
echo scheduled tasks, Docker containers, database volumes
|
|
echo and the '%ROOT_FOLDER_NAME%' setup folder
|
|
echo [2] Manual / Custom - Choose step-by-step what to keep or delete
|
|
echo [0] Cancel
|
|
echo.
|
|
set "UNINSTALL_MODE="
|
|
set /p UNINSTALL_MODE="Enter your choice [1 / 2 / 0]: "
|
|
|
|
if "%UNINSTALL_MODE%"=="0" (
|
|
echo Uninstall cancelled.
|
|
pause
|
|
exit /b 0
|
|
)
|
|
|
|
set "AUTO_WIPE=0"
|
|
if "%UNINSTALL_MODE%"=="1" (
|
|
set "AUTO_WIPE=1"
|
|
echo.
|
|
echo [WARNING] Option 1 selected: ALL Kiosk settings, user profiles, browser data,
|
|
echo and local database volumes will be permanently wiped!
|
|
set "CONFIRM_WIPE="
|
|
set /p CONFIRM_WIPE="Type YES to confirm full automatic wipe: "
|
|
if /i not "!CONFIRM_WIPE!"=="YES" (
|
|
echo Uninstall cancelled.
|
|
pause
|
|
exit /b 0
|
|
)
|
|
) else if not "%UNINSTALL_MODE%"=="2" (
|
|
echo [ERROR] Invalid selection. Exiting.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
:: ============================================================================
|
|
:: 1. DETECT CURRENT KIOSK ACCOUNT & DISABLE AUTO-LOGON
|
|
:: ============================================================================
|
|
echo.
|
|
echo [1/5] Disabling Windows Auto-Logon and Edge Kiosk policies...
|
|
|
|
set "KIOSK_USER="
|
|
for /f "tokens=2*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "DefaultUserName" 2^>nul') do set "KIOSK_USER=%%B"
|
|
|
|
set "WINLOGON_KEY=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
|
|
reg add "%WINLOGON_KEY%" /v "AutoAdminLogon" /t REG_SZ /d "0" /f >nul 2>&1
|
|
reg delete "%WINLOGON_KEY%" /v "DefaultPassword" /f >nul 2>&1
|
|
reg delete "%WINLOGON_KEY%" /v "AutoLogonCount" /f >nul 2>&1
|
|
reg add "%WINLOGON_KEY%" /v "Shell" /t REG_SZ /d "explorer.exe" /f >nul 2>&1
|
|
reg delete "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "Shell" /f >nul 2>&1
|
|
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v "Shell" /f >nul 2>&1
|
|
|
|
set "EDGE_POL=HKLM\SOFTWARE\Policies\Microsoft\Edge"
|
|
reg delete "%EDGE_POL%" /v "InPrivateModeAvailability" /f >nul 2>&1
|
|
reg delete "%EDGE_POL%" /v "ClearBrowsingDataOnExit" /f >nul 2>&1
|
|
reg delete "%EDGE_POL%" /v "RestoreOnStartup" /f >nul 2>&1
|
|
|
|
:: ============================================================================
|
|
:: 2. REMOVE OR RESTORE DEDICATED KIOSK USER ACCOUNT
|
|
:: ============================================================================
|
|
echo [2/5] Handling dedicated Kiosk user account...
|
|
|
|
if "%KIOSK_USER%"=="" goto :NO_KIOSK_USER
|
|
if /i "%KIOSK_USER%"=="%USERNAME%" goto :NO_KIOSK_USER
|
|
if /i "%KIOSK_USER%"=="Administrator" goto :NO_KIOSK_USER
|
|
|
|
echo Detected Kiosk account: "%KIOSK_USER%"
|
|
for /f "tokens=3" %%S in ('query user "%KIOSK_USER%" 2^>nul ^| findstr /i "%KIOSK_USER%"') do logoff %%S >nul 2>&1
|
|
timeout /t 2 /nobreak >nul
|
|
|
|
set "DEL_USER=Y"
|
|
if "%AUTO_WIPE%"=="0" (
|
|
set /p DEL_USER="Delete Kiosk user account '%KIOSK_USER%' and its profile? (Y=Delete / N=Restore Desktop): "
|
|
)
|
|
|
|
if /i "%DEL_USER%"=="Y" (
|
|
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
|
"$u='%KIOSK_USER%';" ^
|
|
"$acc=Get-LocalUser -Name $u -ErrorAction SilentlyContinue;" ^
|
|
"if ($acc) {" ^
|
|
" $sid=$acc.SID.Value;" ^
|
|
" Get-CimInstance Win32_UserProfile -Filter \"SID='$sid'\" -ErrorAction SilentlyContinue | Remove-CimInstance -ErrorAction SilentlyContinue;" ^
|
|
" Remove-LocalUser -Name $u -ErrorAction SilentlyContinue" ^
|
|
"}"
|
|
echo - Removed Kiosk user "%KIOSK_USER%" and its local profile.
|
|
) else (
|
|
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
|
"$u='%KIOSK_USER%';" ^
|
|
"$acc=Get-LocalUser -Name $u -ErrorAction SilentlyContinue;" ^
|
|
"if ($acc) {" ^
|
|
" $sid=$acc.SID.Value;" ^
|
|
" $p=(Get-ItemProperty \"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$sid\" -ErrorAction SilentlyContinue).ProfileImagePath;" ^
|
|
" if ($p -and (Test-Path \"$p\NTUSER.DAT\")) {" ^
|
|
" $loaded=$false;" ^
|
|
" if (-not (Test-Path \"Registry::HKEY_USERS\$sid\")) {" ^
|
|
" reg.exe load \"HKU\$sid\" \"$p\NTUSER.DAT\" >$null 2>&1;" ^
|
|
" if ($LASTEXITCODE -eq 0) { $loaded=$true }" ^
|
|
" }" ^
|
|
" if (Test-Path \"Registry::HKEY_USERS\$sid\") {" ^
|
|
" reg.exe delete \"HKU\$sid\Software\Microsoft\Windows\CurrentVersion\Policies\System\" /v Shell /f >$null 2>&1;" ^
|
|
" reg.exe delete \"HKU\$sid\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\" /v Shell /f >$null 2>&1;" ^
|
|
" $stuckPath=\"Registry::HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3\";" ^
|
|
" if (Test-Path $stuckPath) { $v=(Get-ItemProperty -Path $stuckPath -Name Settings).Settings; $v[8]=2; Set-ItemProperty -Path $stuckPath -Name Settings -Value $v }" ^
|
|
" }" ^
|
|
" if ($loaded) { [gc]::Collect(); Start-Sleep 1; reg.exe unload \"HKU\$sid\" >$null 2>&1 }" ^
|
|
" }" ^
|
|
"}"
|
|
echo - Restored normal Windows Desktop shell and taskbar for "%KIOSK_USER%".
|
|
)
|
|
goto :AFTER_KIOSK_USER
|
|
|
|
:NO_KIOSK_USER
|
|
echo - No separate Kiosk user account needed removal.
|
|
:AFTER_KIOSK_USER
|
|
|
|
:: ============================================================================
|
|
:: 3. REMOVE SCHEDULED TASKS AND KIOSK LOCAL FILES
|
|
:: ============================================================================
|
|
echo [3/5] Removing scheduled tasks and local Kiosk app files...
|
|
schtasks /delete /tn "WSL Docker Startup" /f >nul 2>&1
|
|
schtasks /delete /tn "DTS_Torque_Vault_Kiosk" /f >nul 2>&1
|
|
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "DTS_Master_Setup" /f >nul 2>&1
|
|
|
|
if exist "%KIOSK_APP_DIR%" rmdir /s /q "%KIOSK_APP_DIR%" >nul 2>&1
|
|
|
|
if exist "%KIOSK_DATA_DIR%" (
|
|
set "DEL_BROWSER=Y"
|
|
if "%AUTO_WIPE%"=="0" (
|
|
set /p DEL_BROWSER="Delete persistent Kiosk browser data at %KIOSK_DATA_DIR%? (Y/N): "
|
|
)
|
|
if /i "!DEL_BROWSER!"=="Y" (
|
|
rmdir /s /q "%KIOSK_DATA_DIR%" >nul 2>&1
|
|
echo - Removed %KIOSK_DATA_DIR%
|
|
) else (
|
|
echo - Preserved %KIOSK_DATA_DIR%
|
|
)
|
|
)
|
|
|
|
:: ============================================================================
|
|
:: 4. RESTORE DEFAULT WINDOWS POWER PLAN AND UPDATE POLICIES
|
|
:: ============================================================================
|
|
echo [4/5] Restoring default Balanced Power Plan and Windows Update settings...
|
|
powercfg -setactive 381b4222-f694-41f0-9685-ff5bb260df2e >nul 2>&1
|
|
reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "NoAutoRebootWithLoggedOnUsers" /f >nul 2>&1
|
|
reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v "AUOptions" /f >nul 2>&1
|
|
|
|
if "%AUTO_WIPE%"=="1" if exist "%USERPROFILE%\.wslconfig" del /f /q "%USERPROFILE%\.wslconfig" >nul 2>&1 & echo - Removed custom .wslconfig.
|
|
|
|
:: ============================================================================
|
|
:: 5. STOP AND REMOVE WALMART DOCKER CONTAINERS
|
|
:: ============================================================================
|
|
echo [5/5] Checking WSL Docker containers...
|
|
wsl -d %WSL_DISTRO% -u root true >nul 2>&1
|
|
if %errorLevel% neq 0 goto :UNINSTALL_DONE
|
|
|
|
set "STOP_DOCKER=Y"
|
|
if "%AUTO_WIPE%"=="0" (
|
|
set /p STOP_DOCKER="Stop and remove Walmart Docker containers in %PROJECT_DIR%? (Y/N): "
|
|
)
|
|
if /i not "%STOP_DOCKER%"=="Y" goto :UNINSTALL_DONE
|
|
|
|
set "DEL_VOLUMES=Y"
|
|
if "%AUTO_WIPE%"=="0" (
|
|
set /p DEL_VOLUMES="Also delete database volumes - WARNING deletes all local data? (Y/N): "
|
|
)
|
|
|
|
if /i "%DEL_VOLUMES%"=="Y" (
|
|
wsl -d %WSL_DISTRO% -u root bash -c "cd '%PROJECT_DIR%' 2>/dev/null && docker compose -p '%PROJECT_NAME%' down -v --remove-orphans; rm -rf '%PROJECT_DIR%'"
|
|
echo - Removed containers, database volumes, and %PROJECT_DIR%.
|
|
) else (
|
|
wsl -d %WSL_DISTRO% -u root bash -c "cd '%PROJECT_DIR%' 2>/dev/null && docker compose -p '%PROJECT_NAME%' down --remove-orphans"
|
|
echo - Stopped and removed containers - database volumes preserved.
|
|
)
|
|
|
|
:UNINSTALL_DONE
|
|
set "DEL_SETUP_DIR=N"
|
|
if /i "%ROOT_FOLDER_NAME%"=="mini-pc-setup" (
|
|
if "%AUTO_WIPE%"=="1" (
|
|
set "DEL_SETUP_DIR=Y"
|
|
) else (
|
|
set /p DEL_SETUP_DIR="Delete setup folder '%CLEAN_ROOT%' only? (Y/N): "
|
|
)
|
|
) else (
|
|
echo [INFO] Skipping setup folder deletion because parent folder is '%ROOT_FOLDER_NAME%' - not 'mini-pc-setup'.
|
|
)
|
|
|
|
echo.
|
|
echo ============================================================================
|
|
echo UNINSTALL COMPLETED!
|
|
echo - Windows Auto-Logon and Kiosk restrictions have been removed
|
|
echo - Normal Windows Desktop and Power/Update policies restored
|
|
echo ============================================================================
|
|
echo.
|
|
|
|
set "REBOOT_NOW="
|
|
set /p REBOOT_NOW="Reboot now to apply all changes cleanly? (Y/N): "
|
|
|
|
if /i "%DEL_SETUP_DIR%"=="Y" (
|
|
echo Cleaning up '%CLEAN_ROOT%' in 2 seconds - other folders in parent directory remain untouched...
|
|
cd /d "%TEMP%"
|
|
if /i "%REBOOT_NOW%"=="Y" (
|
|
start "" /b cmd /c "timeout /t 2 /nobreak >nul & rmdir /s /q "%CLEAN_ROOT%" & shutdown /r /t 2"
|
|
) else (
|
|
start "" /b cmd /c "timeout /t 2 /nobreak >nul & rmdir /s /q "%CLEAN_ROOT%""
|
|
)
|
|
exit /b 0
|
|
)
|
|
|
|
if /i "%REBOOT_NOW%"=="Y" shutdown /r /t 3
|
|
pause |