

set DelTreeLog=logs\DeleteDirectoryTree.log

echo ------------------------------------------------------------- >> %DelTreeLog%
echo This log file contains information on full directory removals. >> %DelTreeLog%
echo. >> %DelTreeLog%
echo Unlike DeleteFiles.exe, DeleteDirectoryTree uses the rd /s/q >> %DelTreeLog%
echo command line which deletes any and all files and folders. >> %DelTreeLog%
echo. >> %DelTreeLog%
echo For folder deletions but not new content, plase use  >> %DelTreeLog%
echo Deletefiles.exe to prevent deletions of unintended files >> %DelTreeLog%
echo ------------------------------------------------------------- >> %DelTreeLog%

rem -------------------------- VIRUS DEFINITIONS ---------------------------------
for /f "tokens=3*" %%s in ('reg query ^"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders^" /v ^"Common AppData^"') do (
	set CommonAppData=%%t
)

if exist "%CommonAppData%\Symantec\Definitions" (
	echo y| cacls "%CommonAppData%\Symantec\Definitions" /G administrators:F /T >> %DelTreeLog% 
	rd /s /q "%CommonAppData%\Symantec\Definitions" >> %DelTreeLog%
)
if exist "%CommonAppData%\Symantec\Cached Installs" (
	echo y| cacls "%CommonAppData%\Symantec\Cached Installs" /G administrators:F /T >> %DelTreeLog%
	rd /s /q "%CommonAppData%\Symantec\Cached Installs" >> %DelTreeLog%
)
if exist "%CommonAppData%\Symantec\SPBBC" (
	echo y| cacls "%CommonAppData%\Symantec\SPBBC" /G administrators:F /T >> %DelTreeLog%
	rd /s /q "%CommonAppData%\Symantec\SPBBC" >> %DelTreeLog%
)
if exist "%CommonAppData%\Symantec\SRTSP" (
	echo y| cacls "%CommonAppData%\Symantec\SRTSP" /G administrators:F /T >> %DelTreeLog%
	rd /s /q "%CommonAppData%\Symantec\SRTSP" >> %DelTreeLog%
)
if exist "%CommonAppData%\Symantec\SyKnAppS" (
	echo y| cacls "%CommonAppData%\Symantec\SyKnAppS" /G administrators:F /T >> %DelTreeLog%
	rd /s /q "%CommonAppData%\Symantec\SyKnAppS" >> %DelTreeLog%
)
if exist "%CommonAppData%\Symantec\SymNetDrv" (
	echo y| cacls "%CommonAppData%\Symantec\SymNetDrv" /G administrators:F /T >> %DelTreeLog%
	rd /s /q "%CommonAppData%\Symantec\SymNetDrv" >> %DelTreeLog%
)
if exist "%CommonAppData%\Symantec\Symantec Endpoint Protection" (
	echo y| cacls "%CommonAppData%\Symantec\Symantec Endpoint Protection" /G administrators:F /T >> %DelTreeLog%
	rd /s /q "%CommonAppData%\Symantec\Symantec Endpoint Protection" >> %DelTreeLog%
)

IF NOT EXIST "%CommonFilesDir%\Symantec Shared\VirusDefs\*.*" goto IDS
set UsageDatFile="%CommonFilesDir%\Symantec Shared\VirusDefs\usage.dat"
if not exist %UsageDatFile% goto remove_vdefs

type %UsageDatFile% | find "SMSMSE" > NUL
if %errorlevel%==0 goto IDS

type %UsageDatFile% | find "SAVFMSE_SP" > NUL
if %errorlevel%==0 goto IDS

type %UsageDatFile% | find "SMSDOM"> NUL
if %errorlevel%==0 goto IDS

:remove_vdefs

rem at this point, the above folder exists...now its time to delete the folder and all its contents
rd /s/q "%CommonFilesDir%\Symantec Shared\VirusDefs"
echo %CommonFilesDir%\Symantec Shared\VirusDefs\*.* deleted >> %DelTreeLog%

:IDS

rem --------------------------- IDS DEFINITIONS -----------------------------

IF NOT EXIST "%CommonFilesDir%\Symantec Shared\SymcData\scfidsdefs\*.*" goto SymprotectKC

rem at this point, the above folder exists...now its time to delete the folder and all its contents
rd /s/q "%CommonFilesDir%\Symantec Shared\SymcData\scfidsdefs"
echo %CommonFilesDir%\Symantec Shared\SymcData\scfidsdefs\*.* deleted >> %DelTreeLog%

:SymprotectKC

rem --------------------------- Symprotect KC files -----------------------------

IF NOT EXIST "%CommonFilesDir%\Symantec Shared\SPBBC\*.*" goto AVCerts

rem at this point, the above folder exists...now its time to delete the folder and all its contents
rd /s/q "%CommonFilesDir%\Symantec Shared\SPBBC"
echo %CommonFilesDir%\Symantec Shared\SPBBC\*.* deleted >> %DelTreeLog%

	
:AVCerts

rem --------------------------- AV Root Certificates -----------------------------

IF NOT EXIST "%SAVCE%\pki\certs\*.*" goto AVCerts2

rem at this point, the above folder exists...now its time to delete the folder and all its contents
rd /s/q "%SAVCE%\pki"
echo %SAVCE%\pki\*.* deleted >> %DelTreeLog%


:AVCerts2

IF NOT EXIST "%SAVCE%\pki\roots\*.*" goto AVCerts3

rem at this point, the above folder exists...now its time to delete the folder and all its contents
rd /s/q "%SAVCE%\pki"
echo %SAVCE%\pki\*.* deleted >> %DelTreeLog%

:AVCerts3

IF NOT EXIST "%NAVNT%\pki\*.*" goto AVCerts4

rem at this point, the above folder exists...now its time to delete the folder and all its contents
rd /s/q "%NAVNT%\pki"
echo %NAVNT%\pki\*.* deleted >> %DelTreeLog%


:AVCerts4


IF NOT EXIST "%SAV Install Directory%\pki\certs\*.*" goto VDB

rem at this point, the above folder exists...now its time to delete the folder and all its contents
rd /s/q "%SAV Install Directory%\pki"
echo %SAV Install Directory%\pki\*.* deleted >> %DelTreeLog%



:VDB
	
rem --------------------------- VDBS and XDBS -----------------------------

IF NOT EXIST "%SAV Install Directory%\I2_LDVP.VDB\*.*" goto SEPAppData

rem at this point, the above folder exists...now its time to delete the folder and all its contents
rd /s/q "%SAV Install Directory%\I2_LDVP.VDB"
echo %SAV Install Directory%\I2_LDVP.VDB\*.* deleted >> %DelTreeLog%


:SEPAppData

if "%SEPAppDataDir%" == ""  goto Quarantined
if exist "%SEPAppDataDir%" (
   if exist "%SEPAppDataDir%\..\CurrentVersion" rmdir "%SEPAppDataDir%\..\CurrentVersion"
   if exist AutoDeleteFiles_AppData_FOLDER.txt del AutoDeleteFiles_AppData_FOLDER.txt
   dir /s /b /a-d "%SEPAppDataDir%" >> AutoDeleteFiles_AppData_FOLDER.txt
   call DeleteFiles.exe AutoDeleteFiles_AppData_FOLDER.txt >> %DelTreeLog% 2>&1
   if exist AutoDeleteFolders_AppData_FOLDER.txt del AutoDeleteFolders_AppData_FOLDER.txt
   dir /s /b /ad "%SEPAppDataDir%" | sort /r >> AutoDeleteFolders_AppData_FOLDER.txt
   echo.%SEPAppDataDir% >> AutoDeleteFolders_AppData_FOLDER.txt
   call DeleteFiles.exe AutoDeleteFolders_AppData_FOLDER.txt >> %DelTreeLog% 2>&1
)


:Quarantined
rem -----------------  Quarantined items -------------------------
echo Checking Quarantined items >> %DelTreeLog%
echo Silent Mode = %silent%  >> %DelTreeLog%
rem for silent mode, we'll delete the quarantine items. If not silent mode, the MSI uninstaller will prompt user to delete them
IF %silent% == 0 goto POLICY
IF NOT EXIST "%Common AppData%\Symantec\Symantec AntiVirus Corporate Edition\7.5\Quarantine\*.*" goto POLICY

rem at this point, the above folder exists...now its time to delete the folder and all its contents
rd /s/q "%Common AppData%\Symantec\Symantec AntiVirus Corporate Edition\7.5\Quarantine"
echo %Common AppData%\Symantec\Symantec AntiVirus Corporate Edition\7.5\Quarantine\*.* deleted >> %DelTreeLog%

:POLICY
echo Checking Policy files >> %DelTreeLog%
IF NOT EXIST "%Common AppData%\Symantec\Symantec AntiVirus Corporate Edition\7.5\SCFPolcy\*.*" goto GEH

rem at this point, the above folder exists...now its time to delete the folder and all its contents
rd /s/q "%Common AppData%\Symantec\Symantec AntiVirus Corporate Edition\7.5\SCFPolcy"
echo %Common AppData%\Symantec\Symantec AntiVirus Corporate Edition\7.5\SCFPolcy\*.* deleted >> %DelTreeLog%

:GEH
IF NOT EXIST "%CommonFilesDir%\Symantec Shared\Global Exceptions\*.*" goto notify
rd /s /q "%CommonFilesDir%\Symantec Shared\Global Exceptions"

:notify

rem echo FOLDERS NOT FOUND...
rem IF NOT EXIST "%CommonProgramFiles%\Symantec Shared\VirusDefs\*.*" echo %CommonProgramFiles%\Symantec Shared\VirusDefs not present >> %DelTreeLog%
rem IF NOT EXIST "%CommonProgramFiles%\Symantec Shared\SymcData\scfidsdefs\*.*" echo %CommonProgramFiles%\Symantec Shared\SymcData\scfidsdefs not present >> %DelTreeLog%
rem IF NOT EXIST "%CommonProgramFiles%\Symantec Shared\SPBBC\*.*" echo %CommonProgramFiles%\Symantec Shared\SPBBC not present >> %DelTreeLog%
rem IF NOT EXIST "%CommonProgramFiles%\Symantec Client Security\Symantec AntiVirus\pki\roots\*.* " echo %CommonProgramFiles%\Symantec Client Security\Symantec AntiVirus\pki\roots not present >> %DelTreeLog%


:exit
