@echo off
pushd %~dp0
color 1f
title Remove AutoKMS tasks script -murph
:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo:
echo   Requesting Administrative Privileges...
echo   Press YES in UAC Prompt to Continue
echo:

    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    pushd "%CD%"
    CD /D "%~dp0"
:--------------------------------------
SCHTASKS /DELETE /F /TN "AutoKMS"
if %errorlevel% NEQ 0 (
SCHTASKS /DELETE /F /TN "AutoKMSCustom"
)
if %errorlevel% NEQ 0 (
echo.&echo ERROR - Script is reporting errors when attempting to remove AutoKMS tasks. The tasks likely do not exist
) ELSE (
echo.&echo Script is not reporting errors when attempting to remove AutoKMS tasks. You may delete the files safely.
)
echo.&echo Press any key to exit.
pause>NUL