$ErrorActionPreference = "Stop"

function Test-IsAdmin {
    $identity = [Security.Principal.WindowsIdentity]::GetCurrent()
    $principal = New-Object Security.Principal.WindowsPrincipal($identity)
    return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}

if (-not (Test-IsAdmin)) {
    Write-Host "Administrator privileges are required. Requesting elevation..."

    Start-Process powershell.exe `
        -Verb RunAs `
        -ArgumentList "-ExecutionPolicy Bypass -File `"$PSCommandPath`""

    exit
}

Write-Host "Enabling Acushield services..."

sc.exe config "Acushield Helper" start= auto
sc.exe config "Acushield Service" start= auto

sc.exe failure "Acushield Helper" reset= 60 actions= restart/1000/restart/2500/restart/5000
sc.exe failureflag "Acushield Helper" 1

sc.exe failure "Acushield Service" reset= 60 actions= restart/1000/restart/2500/restart/5000
sc.exe failureflag "Acushield Service" 1

sc.exe start "Acushield Helper"
sc.exe start "Acushield Service"

Write-Host "Acushield enabled."
