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

set OPT=..\optional
set SOFTWARE=..\software
set MSI=chrome-setup.msi
set CONFIG=config\chrome.reg
set SCRIPTS=..\scripts

if NOT EXIST %SOFTWARE%\%MSI% (
  echo ERROR: %SOFTWARE%\%MSI% not found!
  exit /b
)

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

cd %SOFTWARE%
msiexec /uninstall %MSI% /passive
@echo on
msiexec /i %MSI% /passive
@echo off
cd %OPT%

echo importing registry settings ...
reg import %CONFIG%

rem unpin chrome icon from taskbar ...
echo.
call %SCRIPTS%\unpin-taskbar-icons.cmd
echo.

echo disabling update tasks ...
powershell -Command "get-scheduledtask | where TaskName -like 'Google*' | Disable-ScheduledTask"

echo renaming chrome desktop shortcut ...
move /Y %PUBLIC%\Desktop\"Google Chrome.lnk" %PUBLIC%\Desktop\Chrome.lnk 2>nul

echo sleeping 5 seconds ...
ping 127.0.0.1 -n 5 > NUL 2>&1

echo cleanup ...
del /F /Q "%USERPROFILE%\Desktop\Google Chrome.lnk" 2>nul

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

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

