@echo off
::todo add hardware_log.exe before capturing.
setlocal

for /f "usebackq delims==" %%i IN ('%0') DO @set _dpZipDir=%%~di%%~pi
set _rand=%RANDOM%%RANDOM%
set _nvTempRoot=%temp%\%_rand%
set _nvTempZipDir=%_nvTempRoot%\zip
set _nvTempDir=%_nvTempRoot%\data
set _VbsZipScript=%_nvTempRoot%\zip.vbs
set _VbsMsgBoxScript=%_nvTempRoot%\msgbox.vbs

set _ZipFileName=DataplexLogs
set _ZipFileSpec=%_nvTempZipDir%\%_ZipFileName%.zip
set _ZipTmpFileName=%_ZipFileName%._zip
set _dpInstallDir=%ProgramFiles%\Dataplex\CacheFilter

md "%_nvTempDir%"
md "%_nvTempZipDir%"
echo Set objArgs = WScript.Arguments >> "%_VbsZipScript%"
echo srcFolder = objArgs(0) >> "%_VbsZipScript%"
echo ZipFile =  objArgs(1) >> "%_VbsZipScript%"
echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" + Chr(5) + Chr(6) + String(18, vbNullChar) >> "%_VbsZipScript%"
echo Set objShell = CreateObject("Shell.Application") >> "%_VbsZipScript%"
echo Set source = objShell.NameSpace(srcFolder).Items >> "%_VbsZipScript%"
echo objShell.NameSpace(ZipFile).CopyHere(source) >> "%_VbsZipScript%"
echo wScript.Sleep 2000 >> "%_VbsZipScript%"

call :getRegEntry nvelodiskfltr
call :getRegEntry nveloportfltr
call :getRegEntry nvelosvc
call :getRegEntry Dataplex 1

pushd "%_nvTempDir%"

if exist "%_dpInstallDir%"\hardware_log.txt copy /y "%_dpInstallDir%"\hardware_log.txt .\*.* >nul:
if NOT exist "%_dpInstallDir%\addfilter.exe" goto L1
call "%_dpInstallDir%\addfilter.exe" /dflog
move "%_dpInstallDir%\Dataplex.DiskFltr.log" . >nul:
call "%_dpInstallDir%\addfilter.exe" /listdevices /debug > .\addfilter.current.log
call "%_dpInstallDir%\addfilter.exe" /intstatus /debug > .\addfilter.status.log
call "%_dpInstallDir%\addfilter.exe" /details /debug > .\addfilter.details.log

date/T > addfilter.listdevices.log
time/T >> addfilter.listdevices.log
call "%_dpInstallDir%\addfilter.exe" /listdevices >> addfilter.listdevices.log
copy /y "%_dpInstallDir%\*.log" . >nul:
:L1
if exist "%temp%"\dataplex.log     copy /y "%temp%"\dataplex.log           .\Dataplex.install.log >nul:
if exist "%temp%"\dataplex.msi.log copy /y "%temp%"\dataplex.msi.log       .\Dataplex.msi_temp.log >nul:
if exist "%temp%"\dataplex.addfilter.log copy /y "%temp%"\dataplex.addfilter.log       .\Dataplex.addfilter_temp.log >nul:
copy /y %windir%\temp\dataplex.log   .\Dataplex.svc.log >nul:
call msinfo32 /nfo                   .\computer.NFO
CScript  "%_VbsZipScript%"  "%_nvTempDir%" "%_ZipFileSpec%"
copy /b /y "%_nvTempZipDir%\*.zip" "%_dpZipDir%\%_ZipTmpFileName%" >nul:
popd

if not EXIST "%_dpZipDir%\%_ZipTmpFileName%" goto :L50
set _msgBoxString="Please email the file:" + Chr(13) + Chr(10) + Chr(13) + Chr(10)  + "   %_dpZipDir%%_ZipTmpFileName%"  + Chr(13) + Chr(10) + Chr(13) + Chr(10) + "to Dataplex technical support.  Thank you."
goto :L80
:L50
set _msgBoxString="An error was  encountered attempting to generate Dataplex support information."
:L80

echo MsgBox %_msgBoxString% , vbOkOnly+vbSystemModal  >> %_VbsMsgBoxScript%

CScript  "%_VbsMsgBoxScript%"  
rd/s/q "%_nvTempRoot%" 

goto :eof

:getRegEntry 

set __tmpRegFile=%RANDOM%.reg
set __tmpRegFilePath=%windir%\system32
set __tmpRegFileSpec=%__tmpRegFilePath%\%__tmpRegFile%


pushd %__tmpRegFilePath%
if     [%2] == [] call regedit /E %__tmpRegFile% "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\%1"
if NOT [%2] == [] call regedit /E %__tmpRegFile% "HKEY_LOCAL_MACHINE\Software\Dataplex"
popd
if not EXIST "%__tmpRegFileSpec%" goto :L100

move "%__tmpRegFileSpec%" "%_nvTempDir%\%1.reg" >nul:
ren "%_nvTempDir%\%1.reg" *._reg

:L100
goto :eof

