-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSetup (Run Once As Admin).bat
More file actions
54 lines (47 loc) · 1.69 KB
/
Setup (Run Once As Admin).bat
File metadata and controls
54 lines (47 loc) · 1.69 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
@echo off
setlocal
:: Check admin
net session >nul 2>&1
if %errorlevel% neq 0 (
echo ERROR: This setup must be run as Administrator.
echo Right-click this file and choose "Run as administrator".
pause
exit /b 1
)
set "TASK_NAME=SentinelAudit"
set "NODE_EXE=C:\Program Files\nodejs\node.exe"
set "SERVER_JS=%~dp0server.js"
set "WORK_DIR=%~dp0"
echo ============================================
echo Sentinel Audit — One-Time Setup
echo ============================================
echo.
echo Registering scheduled task with admin privileges...
echo Task: %TASK_NAME%
echo Node: %NODE_EXE%
echo Server: %SERVER_JS%
echo.
:: Delete existing task if any
schtasks /delete /tn "%TASK_NAME%" /f >nul 2>&1
:: Create task via PowerShell (more reliable than schtasks XML)
powershell -NoProfile -Command ^
"$a = New-ScheduledTaskAction -Execute '%NODE_EXE%' -Argument '\"%SERVER_JS%\"' -WorkingDirectory '%WORK_DIR%';" ^
"$p = New-ScheduledTaskPrincipal -UserId ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name) -RunLevel Highest -LogonType Interactive;" ^
"$s = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 0 -MultipleInstances IgnoreNew;" ^
"Register-ScheduledTask -TaskName '%TASK_NAME%' -Action $a -Principal $p -Settings $s -Force | Out-Null;" ^
"Write-Host 'Task registered.'"
if %errorlevel% neq 0 (
echo.
echo ERROR: Failed to register task.
pause
exit /b 1
)
echo.
echo ============================================
echo Setup complete!
echo.
echo You can now double-click SentinelAudit.exe
echo on your Desktop - NO admin prompt, ever.
echo ============================================
echo.
pause