-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlock_v3_generator.bat
More file actions
90 lines (81 loc) · 3.52 KB
/
Copy pathlock_v3_generator.bat
File metadata and controls
90 lines (81 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
@echo off
setlocal enabledelayedexpansion
:: ============================================================
:: PRE‑PARSE ARGUMENTS TO CHECK FOR /QUIET
:: ============================================================
set "quiet=0"
set "args=%*"
if defined args (
for %%a in (%args%) do (
if /i "%%a"=="/quiet" set "quiet=1"
)
)
:: ============================================================
:: AUTO-ELEVATION
:: ============================================================
net session >nul 2>&1
if %errorlevel% neq 0 (
if %quiet%==0 echo Requesting administrator privileges...
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~f0", "%*", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /b
)
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
cd /d "%~dp0"
:: ============================================================
:: PARSE COMMAND LINE ARGUMENTS
:: ============================================================
set "duration=10"
:parse
if "%~1"=="" goto :endparse
if /i "%~1"=="/quiet" (set "quiet=1" & shift & goto :parse)
echo %~1|findstr /r "^[1-9][0-9]*$" >nul && (
set "duration=%~1"
shift
goto :parse
) || (
if /i not "%~1"=="/quiet" goto :endparse
)
:endparse
:: ============================================================
:: MAIN SCRIPT
:: ============================================================
:: Use a randomized file name to prevent collision errors
set "temp_ps=%temp%\LockInputTask_%RANDOM%.ps1"
if %quiet%==0 echo [1/3] Creating secure PowerShell script...
:: Write PowerShell script line-by-line
echo $ErrorActionPreference = "Stop" > "%temp_ps%"
echo $signature = '[DllImport("user32.dll")] public static extern bool BlockInput(bool fBlockIt);' >> "%temp_ps%"
echo try { >> "%temp_ps%"
echo $Win32Utils = Add-Type -MemberDefinition $signature -Name "Win32Utils" -Namespace "Win32" -PassThru -ErrorAction Stop >> "%temp_ps%"
echo } catch { exit 1 } >> "%temp_ps%"
echo $result = $Win32Utils::BlockInput($true) >> "%temp_ps%"
echo if ($result) { >> "%temp_ps%"
echo $total = %duration% >> "%temp_ps%"
echo for ($i = $total; $i -ge 0; $i--) { >> "%temp_ps%"
echo $pct = [math]::Round((($total - $i) / $total) * 100) >> "%temp_ps%"
echo $barLen = [int]($pct / 5) >> "%temp_ps%"
echo $bar = "#" * $barLen + "-" * (20 - $barLen) >> "%temp_ps%"
echo $color = "Green" >> "%temp_ps%"
echo if ($i -le 3) { $color = "Red" } elseif ($i -le 6) { $color = "Yellow" } >> "%temp_ps%"
echo Write-Host "`r[$bar] $pct%% Remaining: $i sec " -ForegroundColor $color -NoNewline >> "%temp_ps%"
echo Start-Sleep -Seconds 1 >> "%temp_ps%"
echo } >> "%temp_ps%"
echo $Win32Utils::BlockInput($false) >> "%temp_ps%"
echo Write-Host "`n[OK] Input Restored." -ForegroundColor Green >> "%temp_ps%"
echo } else { >> "%temp_ps%"
echo Write-Host "`n[FAILED] Input NOT locked. Check Admin rights." -ForegroundColor Red >> "%temp_ps%"
echo Start-Sleep -Seconds 5 >> "%temp_ps%"
echo } >> "%temp_ps%"
:: NEW: Make the script delete ITSELF as soon as it's done executing
echo Remove-Item -Path $MyInvocation.MyCommand.Path -Force -ErrorAction SilentlyContinue >> "%temp_ps%"
:: EXECUTION
if %quiet%==0 echo [2/3] Launching PowerShell...
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%temp_ps%"
:: AUTO-CLOSE
if %quiet%==0 (
echo [3/3] Finished.
timeout /t 1 >nul
)
exit /b