__  __          __   ____      __     _      ____  _____  
 |  \/  |   /\    \ \ / /\ \    / /\   | |    / __ \|  __ \ 
 | \  / |  /  \    \ V /  \ \  / /  \  | |   | |  | | |__) |
 | |\/| | / /\ \    > <    \ \/ / /\ \ | |   | |  | |  _  / 
 | |  | |/ ____ \  / . \    \  / ____ \| |___| |__| | | \ \ 
 |_|  |_/_/    \_\/_/ \_\    \/_/    \_\______\____/|_|  \_\
            

Uninstall_Agent.bat

::7.10.2024  - MaxValor  (Not official script, use it at your own risk..)
:: Heimdal Agent uninstall script - run it from dashboard
@echo off
setlocal
::----------------------------------------------------------------------

:: Set log option (1 to enable logging, 0 to disable logging)
:: (C:\Heimdal\uninstall.txt - only timestamp of uninstall)
set "log=0"

:: Set uninstall password (leave empty if not required)
set "uninstallPassword="



::----------------------------------------------------------------------
if "%log%"=="1" (
    if not exist "C:\Heimdal" (
        mkdir "C:\Heimdal"
    )
    if not exist "C:\Heimdal\uninstall.txt" (
        type nul > "C:\Heimdal\uninstall.txt"
    )
)
set "regPath=HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
set "guid="
for /f "tokens=*" %%i in ('reg query "%regPath%" /s /f "Heimdal Thor Agent" 2^>nul ^| findstr /i "HKEY_LOCAL_MACHINE"') do (
    set "guid=%%i"
)
for /f "tokens=*" %%i in ("%guid%") do (
    for /f "tokens=*" %%j in ("%%~nxi") do (
        set "guid=%%j"
    )
)
if "%uninstallPassword%"=="" (
    MsiExec.exe /X%guid% /qn
) else (
    MsiExec.exe /X%guid% /qn uninstallpassword="%uninstallPassword%"
)
if "%log%"=="1" (
    echo Heimdal uninstalled from dashboard with script on %date% at %time% >> "C:\Heimdal\uninstall.txt"
)
endlocal
pause

::----------------------------------------------------------------------
::7.10.2024  - MaxValor