echo off

set EXE_FILE=not_defined
if "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
	set ICE_REV=40
) else (
	set ICE_REV=01
)

if EXIST ..\..\setup\hpzscr%ICE_REV%.exe SET EXE_FILE=..\..\setup\hpzscr%ICE_REV%.exe
if EXIST hpzscr01.exe SET EXE_FILE=hpzscr%ICE_REV%.exe
if "%EXE_FILE%" == "not_defined" goto MISSING_SCRUBBER_EXE

set SCRUBBER_DAT_FILE=not_defined
if EXIST ..\..\setup\hpwscr13.dat SET SCRUBBER_DAT_FILE=hpwscr13.dat
if EXIST hpwscr13.dat SET SCRUBBER_DAT_FILE=hpwscr13.dat
if "SCRUBBER_DAT_FILE"== "not_defined" goto MISSING_PRODUCT_SCRUBBER_DATFILE

rem !!!!!!! If a level is specified, delete all the trigger/tmp files
if not "%1" == "" del %TEMP%\elionmlk*.tmp

rem !!!!!!! If a level is specified, goto the appropriate level
if "%1" == "1" goto LEVEL1
if "%1" == "2" goto LEVEL2
if "%1" == "3" goto LEVEL3


if EXIST %TEMP%\elionmlk1.tmp goto LEVEL2
rem !!!!!!!!!!!!!!!! BEGIN 1st Level
:LEVEL1
echo "***** Executing Level 1 *****"
copy uninstall.bat %TEMP%\elionmlk1.tmp

rem start /w %EXE_FILE% -datfile %SCRUBBER_DAT_FILE% -unattended -showdisconnect -nocopytotemp -d MsiUninstaller,TaskUninstaller,RemoveProgramUninstaller,ScannerUninstaller,AiONetworkDriveUninstaller,PrinterUninstaller,DriverUninstaller,ServiceUninstaller,PortUninstaller,RsmUninstaller,RegistryUninstaller,FileUninstaller,MonitorUninstaller,ProcessShutdown,WindowShutdown
start /w %EXE_FILE% -datfile %SCRUBBER_DAT_FILE% -unattended -showdisconnect -nocopytotemp -d MsiUninstaller,TaskUninstaller,RemoveProgramUninstaller,PrinterUninstaller,DriverUninstaller,ServiceUninstaller,PortUninstaller,RsmUninstaller,RegistryUninstaller,FileUninstaller,MonitorUninstaller,ProcessShutdown,WindowShutdown -forcereboot

goto EXIT
rem !!!!!!!!!!!!!!!! END 1st Level


rem !!!!!!!!!!!!!!!! BEGIN 2nd Level
:LEVEL2
if EXIST %TEMP%\elionmlk2.tmp goto LEVEL3

copy uninstall.bat %TEMP%\elionmlk2.tmp

echo "***** Executing Level 2 *****"
start /w %EXE_FILE% -datfile %SCRUBBER_DAT_FILE% -unattended -showdisconnect -nocopytotemp -forcereboot


goto EXIT
rem !!!!!!!!!!!!!!!! END 2nd Level


rem !!!!!!!!!!!!!!!! BEGIN 3rd Level
:LEVEL3
rem if EXIST %TEMP%\elionmlk3.tmp goto LEVEL4
echo "***** Executing Level 3 *****"

copy uninstall.bat %TEMP%\elionmlk3.tmp


rem Echo remove HPsoftwareUpdate.msi
rem start /w MsiExec.exe /q /X{BB85ED9C-AFC9-43BD-B8DC-258C3C7DF72E} 
rem start /w MsiExec.exe /q /X{8C6027FD-53DC-446D-BB75-CACD7028A134}
rem Echo remove PSE
rem start /w MsiExec.exe /X{6994491D-D491-48F1-AE1F-E179C1FFFC2F}

rem Echo remove Toolbox.msi (product Code)
start /w MsiExec.exe /X{C9F9BEAE-3963-41D3-B970-CA60C6A71179} 

rem Echo remove MPM.msi
start /w MsiExec.exe /X{6022B4FC-4698-4A62-B9FD-54809A9E06F8}

rem Echo forcereboot
start /w %EXE_FILE% -datfile hpqbud01.dat -unattended -nocopytotemp -forcereboot

start /w %EXE_FILE% -datfile %SCRUBBER_DAT_FILE% -unattended -showdisconnect -nocopytotemp -forcereboot


rem start /w %EXE_FILE% -datfile hpqscr01.dat -unattended -nocopytotemp -noreboot

rem start /w %EXE_FILE% -datfile hpqbud01.dat -unattended -nocopytotemp -noreboot

rem  start /w %EXE_FILE% -datfile hpqbud04.dat -unattended -nocopytotemp -noreboot

rem  start /w %EXE_FILE% -datfile hpqbud05.dat -unattended -nocopytotemp -noreboot

rem  start /w %EXE_FILE% -datfile hpqbud06.dat -unattended -nocopytotemp -noreboot

rem start /w %EXE_FILE% -datfile hpqbud08.dat -unattended -nocopytotemp -noreboot

rem start /w %EXE_FILE% -datfile hpqhsc01.dat -unattended -nocopytotemp -forcereboot

goto EXIT
rem !!!!!!!!!!!!!!!! END 3rd Level


:MISSING_PRODUCT_SCRUBBER_DATFILE
echo "**** Uninstall file not found: hpwscr??.dat ****"
goto EXIT

:MISSING_SCRUBBER_EXE
echo "**** Uninstall file not found: hpzscr01.exe ****"
goto EXIT

:EXIT
