| @echo off
|
| :: ------- Run as Administrator Check -------
|
| >nul 2>&1 net session
|
| if %errorLevel% neq 0 (
|
| echo Requesting administrative privileges...
|
| powershell -Command "Start-Process '%~f0' -Verb runAs"
|
| exit /b
|
| )
|
|
|
| :: ------- Set Execution Policy to RemoteSigned -------
|
| powershell -Command "Set-ExecutionPolicy RemoteSigned -Scope LocalMachine -Force"
|
|
|
| setlocal
|
|
|
| :: Prompt for store location name
|
| set /p storeName=Enter the store location name:
|
|
|
| :: Create Event Logs folder if not exists
|
| if not exist "D:\Event Logs" (
|
| mkdir "D:\Event Logs"
|
| )
|
|
|
| :: Save store name to a text file
|
| echo %storeName% > "D:\Event Logs\store_name.txt"
|
|
|
| :: Folder to store the script
|
| set "scriptFolder=%ProgramData%\MrdiyLogApp"
|
| set "scriptPath=%scriptFolder%\Collect-EventLogs.ps1"
|
| set "taskName=CollectEventLogs"
|
|
|
| :: Create folder and copy the script
|
| mkdir "%scriptFolder%" >nul 2>&1
|
| set "batDir=%~dp0"
|
| copy /Y "%batDir%Collect-EventLogs.ps1" "%scriptPath%" >nul
|
|
|
| :: Create a scheduled task that runs at startup with SYSTEM account
|
| powershell -ExecutionPolicy Bypass -Command "$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-ExecutionPolicy Bypass -File \"%scriptPath%\"'; $trigger = New-ScheduledTaskTrigger -AtStartup; Register-ScheduledTask -TaskName '%taskName%' -Action $action -Trigger $trigger -RunLevel Highest -User 'SYSTEM' -Force"
|
|
|
| echo.
|
| echo ✅ Installed successfully! Will run on every startup as SYSTEM.
|
| pause
|
| endlocal
|