@echo off
IF "%1"=="" GOTO USE_COMPUTERNAME_AS_TARGET
set TARGET=%1
goto SKIP_COMPUTERNAME

:USE_COMPUTERNAME_AS_TARGET
set TARGET=%COMPUTERNAME%


:SKIP_COMPUTERNAME
set SYSDIR=%SystemRoot%
REM set SYSDIR=

IF EXIST "%ProgramFiles%\Trend Micro\OfficeScan Client" set OSCEHOMEDIR=%ProgramFiles%\Trend Micro\OfficeScan Client
IF EXIST "%ProgramFiles(x86)%\Trend Micro\OfficeScan Client" set OSCEHOMEDIR=%ProgramFiles(x86)%\Trend Micro\OfficeScan Client
REM set OSCEHOMEDIR=

REM ///////////////////////////
REM //create temp folder

echo Create temp folder: %TARGET%...
mkdir %TARGET%
echo Time to collect: %date% %time% > %TARGET%\verinfo.txt

REM // remove filever.exe, 7za.exe, pslist.exe for legal license issue
REM //////////////////////////////
REM //get file version information
echo Get TM_CFW file information...
IF NOT EXIST "%SYSDIR%\system32\drivers\TM_CFW.sys" echo ERROR:"%SYSDIR%\system32\drivers\TM_CFW.sys" is not found
REM filever.exe /A /B "%SYSDIR%\system32\drivers\TM_CFW.sys" >> %TARGET%\verinfo.txt

IF NOT EXIST "%OSCEHOMEDIR%\TM_CFW.sys" echo ERROR:"%OSCEHOMEDIR%\TM_CFW.sys" is not found
REM filever.exe /A /B "%OSCEHOMEDIR%\TM_CFW.sys" >> %TARGET%\verinfo.txt

IF NOT EXIST "%SYSDIR%\system32\drivers\tmlwf.sys" goto TMLWF_NOTFOUND
REM filever.exe /A /B "%SYSDIR%\system32\drivers\tmlwf.sys" >> %TARGET%\verinfo.txt
rem copy "%SYSDIR%\system32\drivers\tmlwf.sys" "%TEMP%"
rem filever.exe /A /B "%TEMP%\tmlwf.sys" >> %TARGET%\verinfo.txt
rem del "%TEMP%\tmlwf.sys"
goto TMWFP_VER

:TMLWF_NOTFOUND
echo ERROR:"%SYSDIR%\system32\drivers\tmlwf.sys" is not found
echo ERROR:"%SYSDIR%\system32\drivers\tmlwf.sys" is not found >> %TARGET%\verinfo.txt

:TMWFP_VER
IF NOT EXIST "%SYSDIR%\system32\drivers\tmwfp.sys" goto TMWFP_NOTFOUND
REM filever.exe /A /B "%SYSDIR%\system32\drivers\tmwfp.sys" >> %TARGET%\verinfo.txt
rem copy "%SYSDIR%\system32\drivers\tmwfp.sys" "%TEMP%"
rem filever.exe /A /B "%TEMP%\tmwfp.sys" >> %TARGET%\verinfo.txt
rem del "%TEMP%\tmwfp.sys"
goto CLIENT_VER

:TMWFP_NOTFOUND
echo ERROR:"%SYSDIR%\system32\drivers\tmwfp.sys" is not found
echo ERROR:"%SYSDIR%\system32\drivers\tmwfp.sys" is not found >> %TARGET%\verinfo.txt

:CLIENT_VER
REM filever.exe /A /B "%OSCEHOMEDIR%\tmlwf.sys" >> %TARGET%\verinfo.txt
REM filever.exe /A /B "%OSCEHOMEDIR%\tmwfp.sys" >> %TARGET%\verinfo.txt

echo ============================================================ >> %TARGET%\verinfo.txt
echo Collect OfficeScan client version
REM filever.exe /A /B "%OSCEHOMEDIR%\pccnt.exe" >> %TARGET%\verinfo.txt

echo Collect OfficeScan client files
dir "%OSCEHOMEDIR%" /A /S > %TARGET%\filelist.txt

REM //////////////////////////////
REM //get setupapi.log
echo Copy setupapi.log...
copy "%SYSDIR%\setupapi.log" %TARGET%\setupapi.log

REM //////////////////////////////
REM //get firewall dump
echo Dumping firewall rules...
"%OSCEHOMEDIR%\tmpfw.exe" dump

REM //////////////////////////////
REM //export registry keys
echo Export registry keys...
regedit /E %TARGET%\tmcfw.reg "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tmcfw"
regedit /E %TARGET%\TmPfw.reg "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\tmpfw"
regedit /E %TARGET%\NSC.reg "HKEY_LOCAL_MACHINE\SOFTWARE\TrendMicro\NSC\PFW"


REM /////////////////////////////////
REM //export system information (.nfo file)
REM echo Export system information...
REM start /wait msinfo32.exe /nfo %TARGET%\SysInfo.nfo

REM /////////////////////////////////
REM //copy firewall rule dump
echo Copying the dump file for firewall rules
copy "%OSCEHOMEDIR%\!PfwDump.txt" %TARGET%\!PfwDump.txt

REM /////////////////////////////////
REM //collect process list
echo Collect process list
pslist -t > %TARGET%\process.txt

REM /////////////////////////////////
REM //collect tm_cfw.inf
echo Collect tm_cfw.inf
copy "%OSCEHOMEDIR%\TM_CFW.inf" %TARGET%\


REM ////////////////////////////////
REM //create zip file
echo Compress files...
REM 7za.exe a -tzip %TARGET%.zip %TARGET%\

REM //////////////////////////////
REM //delete temp folder and files
rem echo Delete temp folder...
rem rmdir /S /Q %TARGET%
rem echo Delete filever.exe
rem del filever.exe
rem echo Delete 7za.exe
rem del 7za.exe
rem echo Delete pslist.exe
rem del pslist.exe
echo Log collection finished, please send %TARGET%.zip to OfficeScan team
rem pause

:END