Fix some bugs runtime

This commit is contained in:
2026-11-15 00:00:49 +07:00
parent 27680382fa
commit 5bb53106da
3 changed files with 233 additions and 221 deletions
+96 -77
View File
@@ -1,6 +1,14 @@
@echo off
setlocal EnableDelayedExpansion
:: ============================================================================
:: CONFIGURATION
:: ============================================================================
set "WSL_DISTRO=Ubuntu-22.04"
set "PROJECT_DIR=/opt/walmart"
set "KIOSK_APP_DIR=C:\KioskApp"
set "KIOSK_DATA_DIR=C:\KioskBrowserData"
:: ============================================================================
:: 0. AUTO-ELEVATE TO ADMINISTRATOR
:: ============================================================================
@@ -12,116 +20,127 @@ if %errorLevel% neq 0 (
)
echo ============================================================================
echo DTS TORQUE VAULT - UNINSTALL KIOSK & RESTORE WINDOWS NORMAL MODE
echo DTS TORQUE VAULT - KIOSK MODE UNINSTALLER AND SYSTEM RESTORE
echo ============================================================================
echo.
:: Detect current Auto-Logon user automatically
set "DETECTED_USER="
for /f "tokens=2*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "DefaultUserName" 2^>nul') do set "DETECTED_USER=%%B"
if not "%DETECTED_USER%"=="" (
echo Detected configured Kiosk user: "%DETECTED_USER%"
set /p KIOSK_USER="Enter Kiosk username to restore/remove [Default: %DETECTED_USER%]: "
if "!KIOSK_USER!"=="" set "KIOSK_USER=%DETECTED_USER%"
) else (
set /p KIOSK_USER="Enter Kiosk username to restore/remove (leave blank to skip user restore): "
echo This tool will:
echo 1. Disable Windows Auto-Logon and Kiosk Shell restrictions
echo 2. Remove or restore the dedicated Kiosk user account
echo 3. Remove startup tasks and restore default Power / Update policies
echo 4. Optionally stop and remove Walmart Docker containers
echo.
set /p CONFIRM="Are you sure you want to uninstall Kiosk Mode? (Y/N): "
if /i not "%CONFIRM%"=="Y" (
echo Uninstall cancelled.
pause
exit /b 0
)
:: ============================================================================
:: 1. DETECT CURRENT KIOSK ACCOUNT & DISABLE AUTO-LOGON
:: ============================================================================
echo.
set /p DEL_USER="Do you want to DELETE the local user account '%KIOSK_USER%' completely? (Y/N) [N = Keep user & restore normal Desktop]: "
set /p DEL_DATA="Do you want to DELETE Kiosk app & browser data (C:\KioskApp, C:\KioskBrowserData)? (Y/N): "
set /p DEL_WSL="Do you want to REMOVE Docker containers and Ubuntu-22.04 WSL distro? (Y/N): "
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"
:: ============================================================================
:: 1. DISABLE WINDOWS AUTO-LOGON & CLEAN RUNONCE
:: ============================================================================
echo [1/5] Disabling Windows Auto-Logon...
set "WINLOGON_KEY=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
reg add "%WINLOGON_KEY%" /v "AutoAdminLogon" /t REG_SZ /d "0" /f >nul
reg delete "%WINLOGON_KEY%" /v "DefaultUserName" /f >nul 2>&1
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 "DefaultDomainName" /f >nul 2>&1
reg delete "%WINLOGON_KEY%" /v "AutoLogonCount" /f >nul 2>&1
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "DTS_Master_Setup" /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
:: ============================================================================
:: 2. REMOVE EDGE KIOSK POLICIES
:: ============================================================================
echo [2/5] Removing Microsoft Edge Kiosk policies...
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
:: ============================================================================
:: 3. REMOVE SCHEDULED TASKS
:: 2. REMOVE OR RESTORE DEDICATED KIOSK USER ACCOUNT
:: ============================================================================
echo [3/5] Removing Kiosk and WSL Auto-Start Scheduled Tasks...
schtasks /delete /tn "DTS_WSL_Docker_AutoStart" /f >nul 2>&1
schtasks /delete /tn "DTS_Torque_Vault_Kiosk" /f >nul 2>&1
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 /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 } if ($loaded) { [gc]::Collect(); Start-Sleep 1; reg.exe unload \"HKU\$sid\" >$null 2>&1 } } }"
echo - Restored normal Windows Desktop shell for "%KIOSK_USER%".
)
goto :AFTER_KIOSK_USER
:NO_KIOSK_USER
echo - No separate Kiosk user account needed removal.
:AFTER_KIOSK_USER
:: ============================================================================
:: 4. RESTORE NORMAL DESKTOP SHELL OR DELETE KIOSK USER ACCOUNT
:: 3. REMOVE SCHEDULED TASKS AND KIOSK LOCAL FILES
:: ============================================================================
echo [4/5] Restoring or removing Kiosk user "%KIOSK_USER%"...
if not "%KIOSK_USER%"=="" (
if /i not "%KIOSK_USER%"=="%USERNAME%" (
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$user = '%KIOSK_USER%';" ^
"$delUser = '%DEL_USER%';" ^
"$acc = Get-LocalUser -Name $user -ErrorAction SilentlyContinue;" ^
"if ($acc) {" ^
" $sid = $acc.SID.Value;" ^
" $profReg = \"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$sid\";" ^
" $profilePath = (Get-ItemProperty $profReg -ErrorAction SilentlyContinue).ProfileImagePath;" ^
" if ($profilePath -and (Test-Path (Join-Path $profilePath 'NTUSER.DAT'))) {" ^
" $hivePath = Join-Path $profilePath 'NTUSER.DAT';" ^
" $loaded = $false;" ^
" if (-not (Test-Path \"Registry::HKEY_USERS\$sid\")) { reg load \"HKU\$sid\" \"$hivePath\" >$null 2>&1; if ($LASTEXITCODE -eq 0) { $loaded = $true; } }" ^
" if (Test-Path \"Registry::HKEY_USERS\$sid\") {" ^
" Remove-ItemProperty -Path \"Registry::HKEY_USERS\$sid\Software\Microsoft\Windows\CurrentVersion\Policies\System\" -Name 'Shell' -ErrorAction SilentlyContinue;" ^
" }" ^
" if ($loaded) { [gc]::Collect(); Start-Sleep -Milliseconds 300; reg unload \"HKU\$sid\" >$null 2>&1; }" ^
" }" ^
" if ($delUser -ieq 'Y') {" ^
" Write-Host (' - Deleting user account and profile for ' + $user + '...');" ^
" Get-CimInstance -ClassName Win32_UserProfile | Where-Object { $_.SID -eq $sid } | Remove-CimInstance -ErrorAction SilentlyContinue;" ^
" Remove-LocalUser -Name $user -ErrorAction SilentlyContinue;" ^
" } else {" ^
" Write-Host (' - Normal Windows Desktop restored for ' + $user + '.');" ^
" }" ^
"}"
) else (
echo - Skipping current logged-in Administrator account for safety.
echo [3/5] Removing scheduled tasks and local Kiosk app files...
schtasks /delete /tn "DTS_WSL_Docker_AutoStart" /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 /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%
)
)
:: ============================================================================
:: 5. CLEAN UP KIOSK FOLDERS, POWER PLAN & OPTIONAL WSL/DOCKER REMOVAL
:: 4. RESTORE DEFAULT WINDOWS POWER PLAN AND UPDATE POLICIES
:: ============================================================================
echo [5/5] Restoring Power Plan and cleaning up files...
:: Restore Balanced Power Plan
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 /i "%DEL_DATA%"=="Y" (
echo - Removing C:\KioskApp and C:\KioskBrowserData...
rd /s /q "C:\KioskApp" >nul 2>&1
rd /s /q "C:\KioskBrowserData" >nul 2>&1
)
:: ============================================================================
:: 5. OPTIONAL: 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
if /i "%DEL_WSL%"=="Y" (
echo - Stopping containers and unregistering Ubuntu-22.04 WSL...
wsl -d Ubuntu-22.04 -u root bash -c "cd /opt/walmart && docker compose down -v" >nul 2>&1
wsl --unregister Ubuntu-22.04 >nul 2>&1
set "STOP_DOCKER="
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="
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 down -v && rm -rf %PROJECT_DIR%"
echo - Removed containers, volumes, and %PROJECT_DIR%.
) else (
wsl -d %WSL_DISTRO% -u root bash -c "cd %PROJECT_DIR% 2>/dev/null && docker compose down"
echo - Stopped and removed containers - database volumes preserved.
)
:UNINSTALL_DONE
echo.
echo ============================================================================
echo UNINSTALL COMPLETED! MINI PC RESTORED TO NORMAL WINDOWS MODE.
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 /p REBOOT_NOW="Reboot now to apply changes? (Y/N): "
set "REBOOT_NOW="
set /p REBOOT_NOW="Reboot now to apply all changes cleanly? (Y/N): "
if /i "%REBOOT_NOW%"=="Y" shutdown /r /t 3
pause