@echo off
call check-for-admin
if %ERRORLEVEL% neq 0 exit /b

set CONFIG=config\install-heidisql.txt
set EXE=..\software\heidisql-setup.exe
set STARTMENU="%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs"

if NOT EXIST %EXE% (
  echo ERROR: %EXE% not found!
  exit /b
)

echo ####### %0 #######

echo installing Heidi SQL ...
start /wait %EXE% /LOADINF=%CONFIG% /NORESTART /NOCANCEL /SILENT /SUPPRESSMSGBOXES /CLOSEAPPLICATIONS

echo moving HeidiSQL startmenu shortcut ...
move /Y %STARTMENU%\"HeidiSQL\HeidiSQL.lnk" %STARTMENU%

echo moving HeidiSQL desktop shortcut ...
move /Y "%USERPROFILE%\Desktop\HeidiSQL.lnk" "%PUBLIC%\Desktop"
icacls "%PUBLIC%\Desktop\HeidiSQL.lnk" /grant Users:R 2>nul

echo cleanup ...
rd /S /Q %STARTMENU%\"HeidiSQL"

rem refresh desktop (W10 style)
ie4uinit.exe -show

echo ####### %0 #######
pause

