rem *************************************************************************************
rem  FindApplications
rem
rem    This code looks for Symantec Applications that Cleanwipe knows how to remove.
rem
rem    Any one of the following Applications can be found:
rem
rem      Symantec Enforcement Agent 5.1
rem      Symantec Protection Agent 5.1
rem      Symantec Policy Manager 5.1
rem      Symantec Network Access Control
rem      Symantec Enpoint Protection Manager
rem      Symantec Protection Center
rem      
rem    The following Environment Variables will be set:  
rem      
rem      APPCode        This is the application GUID typically found in the WIN32 Registry at: 
rem                     HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
rem
rem      SAVProduct     This is the name of the found application.
rem
rem      Note: APPCode2 and SAVProduct2 also set in the case the both SEPM and SAV are detected.
rem 
rem      SEA_Folder
rem      SPA_Folder
rem      SPM_Folder     These entries will contain the root install to folder.
rem      SNAC_Folder
rem      SESM_Folder
rem      SCS_Folder
rem      SAV_Folder
rem      NAV_Folder
rem      
rem    In addition, for the found application, a line like the following example
rem    will be added in DeleteFilesEnVar.txt:
rem
rem      %SEA_Folder%	C:\Program Files\Symantec Network Access
rem
rem *************************************************************************************

echo %%CommonProgramFiles%%	%CommonProgramFiles%>>DeleteFilesEnVar.txt

set SEA_Folder=
set SPA_Folder=
set SPM_Folder=
set SNAC_Folder=
set SESM_Folder=
set SSC_Folder=
set SCS_Folder=
set SAV_Folder=
set NAV_Folder=
set LU_Folder=
set REPORTING_AGENTS_Folder=

set APPCode=
set APPCode2=
set APPCode3=
set APPCode4=
set APPCode5=
set APPCode6=
set SAVProduct=
set SAVProduct2=
set SAVProduct2=
set SAVProduct3=
set SAVProduct4=
set SAVProduct5=
set SAVProduct6=

call :TestForLU

rem code in RunCleanWipe Run_MSI method expects that if SPM is found, it is the first product, APPCode, and SAVProduct, so we must to :TestForSPM first
call :TestForSPM

set SAVProductXXX=Symantec Network Access Control
set APP_FolderXXX=C:\Program Files\Symantec\Symantec Endpoint Protection\
call :TestForApp "Symantec Network Access Control" SNAC_Folder "C:\Program Files\Symantec\Symantec Endpoint Protection\SNAC.EXE"

set SAVProductXXX=Symantec Network Access Control
set APP_FolderXXX=C:\Program Files\Symantec\Symantec Endpoint Protection\
call :TestForApp "Symantec Network Access Control Win64" SNAC_Folder "C:\Program Files\Symantec\Symantec Endpoint Protection\SNAC.EXE"

set SAVProductXXX=Symantec Endpoint Protection Manager
set APP_FolderXXX=C:\Program Files\Symantec\Symantec Endpoint Protection Manager\
call :TestForApp "Symantec Endpoint Protection Manager" SESM_Folder "C:\Program Files\Symantec\Symantec Endpoint Protection Manager\tomcat\bin\SemSvc.exe"

set SAVProductXXX=Symantec Endpoint Protection Manager
set APP_FolderXXX=C:\Program Files (x86)\Symantec\Symantec Endpoint Protection Manager\
call :TestForApp64 "Symantec Endpoint Protection Manager" SESM_Folder "C:\Program Files (x86)\Symantec\Symantec Endpoint Protection Manager\tomcat\bin\SemSvc.exe"

set SAVProductXXX=Symantec Protection Center
set APP_FolderXXX=C:\Program Files\Symantec\Symantec Protection Center\
call :TestForApp "Symantec Protection Center" SESM_Folder "C:\Program Files\Symantec\Symantec Protection Center\tomcat\bin\SemSvc.exe"

set SAVProductXXX=Symantec Protection Center
set APP_FolderXXX=C:\Program Files (x86)\Symantec\Symantec Protection Center\
call :TestForApp64 "Symantec Protection Center" SESM_Folder "C:\Program Files (x86)\Symantec\Symantec Protection Center\tomcat\bin\SemSvc.exe"

set SAVProductXXX=Symantec System Center
set APP_FolderXXX=C:\Program Files\Symantec\Symantec System Center\
call :TestForApp "Symantec System Center" SSC_Folder "C:\Program Files\Symantec\Symantec System Center\Symantec System Center.msc"

set SAVProductXXX=Symantec Client Security
set APP_FolderXXX=C:\Program Files\Symantec Client Security\Symantec AntiVirus\
call :TestForApp "Symantec Client Security" SCS_Folder "C:\Program Files\Symantec Client Security\Symantec AntiVirus\Rtvscan.exe"


REM Note: The full name is Reporting Agents (Symantec Corporation) but we only use Reporting Agents
REM       otherwise this was causing RunCleanWipe.bat to have a problem.
set SAVProductXXX=Reporting Agents
set APP_FolderXXX=C:\Program Files\Common Files\Symantec Shared\Reporting Agents\Win32\
call :TestForApp "Reporting Agents (Symantec Corporation)" REPORTING_AGENTS_Folder "C:\Program Files\Common Files\Symantec Shared\Reporting Agents\Win32\ReporterSvc.exe"

set SAVProductXXX=Symantec Endpoint Protection
set APP_FolderXXX=C:\Program Files\Symantec\Symantec Endpoint Protection\
call :TestForApp "Symantec Endpoint Protection" SAV_Folder "C:\Program Files\Symantec\Symantec Endpoint Protection\SmcGui.exe"

set SAVProductXXX=Symantec Endpoint Protection
set APP_FolderXXX=C:\Program Files\Symantec\Symantec Endpoint Protection\
call :TestForApp "Symantec Endpoint Protection Client" SAV_Folder "C:\Program Files\Symantec\Symantec Endpoint Protection\SmcGui.exe"

set SAVProductXXX=Symantec Endpoint Protection
set APP_FolderXXX=C:\Program Files\Symantec\Symantec Endpoint Protection\
call :TestForApp "Symantec Endpoint Protection Win64" SAV_Folder "C:\Program Files\Symantec\Symantec Endpoint Protection\SmcGui.exe"

set SAVProductXXX=Symantec Endpoint Protection
set APP_FolderXXX=C:\Program Files\Symantec\Symantec Endpoint Protection\
call :TestForApp "Symantec Endpoint Protection Small Business Edition" SAV_Folder "C:\Program Files\Symantec\Symantec Endpoint Protection\SmcGui.exe"

REM Note space after name in DC 188
set SAVProductXXX=Symantec Endpoint Protection
set APP_FolderXXX=C:\Program Files\Symantec\Symantec Endpoint Protection\
call :TestForApp "Symantec Endpoint Protection Client " SAV_Folder "C:\Program Files\Symantec\Symantec Endpoint Protection\SmcGui.exe"

REM Note space after name in DC 188
set SAVProductXXX=Symantec Endpoint Protection
set APP_FolderXXX=C:\Program Files\Symantec\Symantec Endpoint Protection\
call :TestForApp "Symantec Endpoint Protection Small Business Edition " SAV_Folder "C:\Program Files\Symantec\Symantec Endpoint Protection\SmcGui.exe"

set SAVProductXXX=Symantec AntiVirus
set APP_FolderXXX=C:\Program Files\Symantec AntiVirus\
call :TestForApp "Symantec AntiVirus" SAV_Folder "C:\Program Files\Symantec AntiVirus\Rtvscan.exe"

set SAVProductXXX=Symantec AntiVirus Win64
set APP_FolderXXX=C:\Program Files (x86)\Symantec AntiVirus\
call :TestForApp "Symantec AntiVirus Win64" SAV_Folder "C:\Program Files (x86)\Symantec AntiVirus\Rtvscan.exe"

set SAVProductXXX=Norton AntiVirus
set APP_FolderXXX=C:\Program Files\Symantec AntiVirus\
call :TestForApp "Norton AntiVirus" NAV_Folder "C:\Program Files\Symantec AntiVirus\Rtvscan.exe"

set SAVProductXXX=Symantec Enforcement Agent 5.1
set APP_FolderXXX=C:\Program Files\Symantec\SEA\
call :TestForApp "Symantec Enforcement Agent 5.1" SEA_Folder "C:\Program Files\Symantec\SEA\SmcGui.exe"

set SAVProductXXX=Symantec Protection Agent 5.1
set APP_FolderXXX=C:\Program Files\Symantec\SPA\
call :TestForApp "Symantec Protection Agent 5.1" SPA_Folder "C:\Program Files\Symantec\SPA\SmcGui.exe"

set SAVProductXXX=
goto :eof

rem *************************************************************************************

:TestForLU
if exist app.txt del /q app.txt
esugreg HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\LiveUpdate" "InstallLocation" -fq >app.txt
if NOT %errorlevel%==0 goto :eof
if not exist app.txt goto :eof
for /f "delims=$" %%a in (app.txt) do set LU_Folder=%%a
echo %%LU_Folder%%	%LU_Folder%>>DeleteFilesEnVar.txt
goto :eof

rem *************************************************************************************

:TestForApp
set APPCodeXXX=
if exist app.txt del /q app.txt
if exist app2.txt del /q app2.txt
esugmsi /search %1 > app.txt
if not exist app.txt goto :TestForApp_x
esugmsi2 <app.txt /search %1 > app2.txt
if not exist app2.txt goto :TestForApp_x
for /f "delims=$" %%a in (app2.txt) do set APPCodeXXX=%%a
if "%APPCodeXXX%"=="" goto :TestForApp_x
esugreg HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%APPCodeXXX%" "InstallLocation" >app2.txt
if NOT %errorlevel%==0 goto :TestForApp_x
if not exist app2.txt goto :TestForApp_x
for /f "delims=$" %%a in (app2.txt) do set APP_Folder=%%a
echo %%%2%%	%APP_Folder%>>DeleteFilesEnVar.txt
set %2=%APP_Folder%
set APP_Folder=
call :SetAppCode
goto :TestForApp_x_done

:TestForApp_x
if exist %3 set APP_Folder=%APP_FolderXXX%
if "%APP_Folder%"=="" goto :TestForApp_x_done
echo %%%2%%	%APP_Folder%>>DeleteFilesEnVar.txt
set %2=%APP_Folder%

:TestForApp_x_done
set APP_Folder=
set APP_FolderXXX=
goto :eof

rem *************************************************************************************

:TestForApp64
set APPCodeXXX=
if exist app.txt del /q app.txt
if exist app2.txt del /q app2.txt
esugmsi /search %1 > app.txt
if not exist app.txt goto :TestForApp64_x
esugmsi2 <app.txt /search %1 > app2.txt
if not exist app2.txt goto :TestForApp64_x
for /f "delims=$" %%a in (app2.txt) do set APPCodeXXX=%%a
if "%APPCodeXXX%"=="" goto :TestForApp64_x
esugreg HKLM "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\%APPCodeXXX%" "InstallLocation" >app2.txt
if NOT %errorlevel%==0 goto :TestForApp64_x
if not exist app2.txt goto :TestForApp64_x
for /f "delims=$" %%a in (app2.txt) do set APP_Folder=%%a
echo %%%2%%	%APP_Folder%>>DeleteFilesEnVar.txt
set %2=%APP_Folder%
set APP_Folder=
call :SetAppCode
goto :TestForApp64_x_done

:TestForApp64_x
if exist %3 set APP_Folder=%APP_FolderXXX%
if "%APP_Folder%"=="" goto :TestForApp64_x_done
echo %%%2%%	%APP_Folder%>>DeleteFilesEnVar.txt
set %2=%APP_Folder%

:TestForApp64_x_done
set APP_Folder=
set APP_FolderXXX=
goto :eof

rem *************************************************************************************

:TestForSPM
set APPCodeXXX=
if exist app.txt del /q app.txt
esugreg HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{DAE05E18-1549-4B01-8A2C-973519A86404}" "UninstallString" >>app.txt
if NOT %errorlevel%==0 goto :eof
esugreg HKLM "SOFTWARE\Sygate\SEM5.0\SyServ" "TargetDir" >app.txt
if NOT %errorlevel%==0 goto :eof
if not exist app.txt goto :eof
for /f "delims=$" %%a in (app.txt) do set SPM_Folder=%%a
if "%SPM_Folder%"=="" set SPM_Folder=C:\Program Files\Symantec\Symantec Policy Manager
echo %%SPM_Folder%%	%SPM_Folder%>>DeleteFilesEnVar.txt
set APPCodeXXX={DAE05E18-1549-4B01-8A2C-973519A86404}
set SAVProductXXX=Symantec Policy Manager
call :SetAppCode
goto :eof

rem *************************************************************************************

:SetAppCode
if NOT "%APPCode%"=="" goto :SetAppCode_2
set APPCode=%APPCodeXXX%
set SAVProduct=%SAVProductXXX%
goto :SetAppCode_done

:SetAppCode_2
if NOT "%APPCode2%"=="" goto :SetAppCode_3
set APPCode2=%APPCodeXXX%
set SAVProduct2=%SAVProductXXX%
goto :SetAppCode_done

:SetAppCode_3
if NOT "%APPCode3%"=="" goto :SetAppCode_4
set APPCode3=%APPCodeXXX%
set SAVProduct3=%SAVProductXXX%
goto :SetAppCode_done

:SetAppCode_4
if NOT "%APPCode4%"=="" goto :SetAppCode_5
set APPCode4=%APPCodeXXX%
set SAVProduct4=%SAVProductXXX%
goto :SetAppCode_done

:SetAppCode_5
if NOT "%APPCode5%"=="" goto :SetAppCode_6
set APPCode5=%APPCodeXXX%
set SAVProduct5=%SAVProductXXX%
goto :SetAppCode_done

:SetAppCode_6
if NOT "%APPCode65%"=="" goto :SetAppCode_7
set APPCode6=%APPCodeXXX%
set SAVProduct6=%SAVProductXXX%
goto :SetAppCode_done

:SetAppCode_7
:SetAppCode_done
if exist app.txt del /q app.txt
if exist app2.txt del /q app2.txt
set APPCodeXXX=
set SAVProductXXX=

goto :eof
