| @echo off |
| |
| rem *************** start of 'main' |
| |
| set DEBUG=0 |
| if "%DEBUG%"=="1" (set TRACE=echo) else (set TRACE=rem) |
| |
| rem Note that right now there is a bug in tracerpt.exe cause of which you might want to use tracefmt.exe instead. |
| |
| set USE_TRACE_FMT=1 |
| %TRACE% The value of variable USE_TRACE_FMT is %USE_TRACE_FMT% |
| |
| rem define variables for each of the switches we support |
| set SWHELP=h |
| set SWMODE=mode |
| set SWTRACELOG=tracelog |
| set SWMOF=mof |
| set SWOUTPUT=o |
| set VALID=0 |
| |
| rem define variables for parameters to be passed to tracerpt |
| set TRACEDIR=%WINDIR%\system32\msdtc\trace |
| set TRACEFILE1=%TRACEDIR%\dtctrace.log |
| set TRACEFILE2=%TRACEDIR%\tracetx.log |
| set MOFFILE=%TRACEDIR%\msdtctr.mof |
| set ERRORFILE=%TRACEDIR%\errortrace.txt |
| set OUTPUTFILE=%TRACEDIR%\trace |
| |
| rem Parse command line and setup variables |
| set CMDLINE=%* |
| %TRACE% About to call PARSECMDLINE with the argument %CMDLINE% |
| call :PARSECMDLINE 0 |
| |
| rem Validate the command line |
| %TRACE% About to call the procedure VALIDATE |
| call :VALIDATE |
| |
| rem if Vaidation fails, we give up |
| if "%VALID%"=="0" ( |
| %TRACE% Parameter validation failed, exiting ... |
| goto :EOF |
| ) |
| |
| rem depending on the value of the mode, set the tracelogfile |
| call :MYFINDSWITCH %SWMODE% |
| if not "%RET%"=="0" ( |
| if "%RETV%"=="1" set TRACEFILE=%TRACEFILE1% |
| if "%RETV%"=="2" set TRACEFILE=%TRACEFILE2% |
| ) |
| |
| rem if the tracelog switch was used, set the tracelogfile |
| call :MYFINDSWITCH %SWTRACELOG% |
| if not "%RET%"=="0" ( |
| set TRACEFILE=%RETV% |
| ) |
| |
| rem if the mof switch was used, set the moffile |
| call :MYFINDSWITCH %SWMOF% |
| if not "%RET%"=="0" ( |
| set MOFFILE=%RETV% |
| ) |
| |
| rem if the output switch was used, set the output file |
| call :MYFINDSWITCH %SWOUTPUT% |
| if not "%RET%"=="0" ( |
| set OUTPUTFILE=%RETV% |
| ) |
| |
| %TRACE% TRACEFILE=%TRACEFILE% |
| %TRACE% MOFFILE=%MOFFILE% |
| %TRACE% OUTPUTFILE=%OUTPUTFILE% |
| |
| rem if the specified tracelogfile does not exist, display an error message and give up |
| if not exist %TRACEFILE% ( |
| echo The tracelogfile %TRACEFILE% does not exist. exiting ... |
| call :HELP |
| goto :EOF |
| ) |
| |
| rem if the specified moffile does not exist, display an error message and give up |
| if not exist %MOFFILE% ( |
| echo The moffile %MOFFILE% does not exist. exiting ... |
| call :HELP |
| goto :EOF |
| ) |
| |
| rem set a variable for output file with extension |
| set OUTPUTFILEWITHEXT=%OUTPUTFILE%.csv |
| %TRACE% The value of variable OUTPUTFILEWITHEXT=%OUTPUTFILEWITHEXT% |
| |
| |
| rem if the specified outputfile exists, ask if the user is ok with it being over-written. |
| |
| if exist %OUTPUTFILEWITHEXT% ( |
| echo The file %OUTPUTFILEWITHEXT% already exists. You may press Control-C to terminate the batch file. Continuing the batch file will overwrite this file. |
| Pause |
| del %OUTPUTFILEWITHEXT% 1>nul 2>nul |
| ) |
| |
| rem if the old error file exists, delete it |
| if exist %ERRORFILE% ( |
| del %ERRORFILE% 1>nul 2>nul |
| %TRACE% Deleted the file %ERRORFILE% |
| ) |
| |
| rem call the utility with the right arguments |
| %TRACE% About to call the utility tracerpt.exe ... |
| |
| if "%USE_TRACE_FMT%"=="0" (goto :USE_TRACEPRT_UTILITY) else (goto :USE_TRACEFMT_UTILITY) |
| |
| :USE_TRACEPRT_UTILITY |
| %TRACE% Entered the USE_TRACEPRT_UTILITY block, about to call traceprt |
| tracerpt %TRACEFILE% -o %OUTPUTFILE% -mof %MOFFILE% > %ERRORFILE% 2>&1 |
| |
| if not exist %OUTPUTFILEWITHEXT% ( |
| %TRACE% The file %OUTPUTFILEWITHEXT% does not exist, therefore exiting ... |
| call :DISPLAY_ERROR_MESSAGE |
| goto :EOF |
| ) |
| notepad %OUTPUTFILEWITHEXT% |
| goto :EOF |
| |
| :USE_TRACEFMT_UTILITY |
| %TRACE% Entered the USE_TRACEFMT_UTILITY block, about to call tracefmt |
| tracefmt %TRACEFILE% -o %OUTPUTFILEWITHEXT% -tmf %MOFFILE% -nosummary > %ERRORFILE% 2>&1 |
| |
| if not exist %OUTPUTFILEWITHEXT% ( |
| %TRACE% The file %OUTPUTFILEWITHEXT% does not exist, therefore exiting ... |
| call :DISPLAY_ERROR_MESSAGE |
| goto :EOF |
| ) |
| notepad %OUTPUTFILEWITHEXT% |
| goto :EOF |
| |
| |
| |
| goto :EOF |
| |
| |
| |
| |
| |
| rem *************** Procedures begin here **************************** |
| |
| rem *************** start of procedure VALIDATE |
| :VALIDATE |
| |
| set ARG=1 |
| set SWHELPFOUND=0 |
| set SWMODEFOUND=0 |
| set SWTRACELOGFOUND=0 |
| set SWMOFFOUND=0 |
| set SWOUTPUTFOUND=0 |
| set OUTNAMENAME=0 |
| |
| rem If no arguments are used at all, don't perform any other validation, just display help and give up |
| if %CMDARGCOUNT% EQU 0 if %CMDSWCOUNT% EQU 0 (call :HELP) & (goto :EOF) |
| |
| rem If not arguments are given, display help |
| if %CMDARGCOUNT% GTR 0 goto ERROR_USED_ARGUMENTS_WITHOUT_SWITCHES |
| |
| rem If the switch SWHELP is used anywhere, don't perform any other validation, just display help and give up |
| call :MYFINDSWITCH %SWHELP% |
| if not "%RET%"=="0" (call :HELP) & (goto :EOF) |
| |
| :SWLOOP |
| if %ARG% GTR %CMDSWCOUNT% goto :SWLOOPEND |
| call :GETSWITCH %ARG% |
| set MYSWITCH=%RET:~1% |
| |
| rem make sure no switch is used twice |
| if /i "%MYSWITCH%"=="%SWHELP%" (if "%SWHELPFOUND%"=="1" (goto ERROR_USED_SAME_SWITCH_TWICE) else (set SWHELPFOUND=1)) |
| if /i "%MYSWITCH%"=="%SWMODE%" (if "%SWMODEFOUND%"=="1" (goto ERROR_USED_SAME_SWITCH_TWICE) else (set SWMODEFOUND=1)) |
| if /i "%MYSWITCH%"=="%SWTRACELOG%" (if "%SWTRACELOGFOUND%"=="1" (goto ERROR_USED_SAME_SWITCH_TWICE) else (set SWTRACELOGFOUND=1)) |
| if /i "%MYSWITCH%"=="%SWMOF%" (if "%SWMOFFOUND%"=="1" (goto ERROR_USED_SAME_SWITCH_TWICE) else (set SWMOFFOUND=1)) |
| if /i "%MYSWITCH%"=="%SWOUTPUT%" (if "%SWOUTPUTFOUND%"=="1" (goto ERROR_USED_SAME_SWITCH_TWICE) else (set SWOUTPUTFOUND=1)) |
| |
| rem make sure that the switches mode and tracelog are not used simultaneously |
| if "%SWMODEFOUND%"=="1" if "%SWTRACELOGFOUND%"=="1" goto ERROR_USED_BOTH_MODE_AND_TRACELOG |
| |
| rem make sure that there is no switch outside our list |
| if /i not "%MYSWITCH%"=="%SWHELP%" ( |
| if /i not "%MYSWITCH%"=="%SWMODE%" ( |
| if /i not "%MYSWITCH%"=="%SWTRACELOG%" ( |
| if /i not "%MYSWITCH%"=="%SWMOF%" ( |
| if /i not "%MYSWITCH%"=="%SWOUTPUT%" ( |
| (echo Invalid Switch "%RET%") & (call :HELP) & (goto :EOF) ))))) |
| set /a ARG+=1 |
| goto :SWLOOP |
| :SWLOOPEND |
| |
| rem make sure that either the switch "-mode" or "-tracelog" was used |
| if "%SWMODEFOUND%"=="0" if "%SWTRACELOGFOUND%"=="0" (echo Invalid Usage : neither "-%SWMODE%" nor "-%SWTRACELOG%" was specified) & (call :HELP) & (goto :EOF) |
| |
| rem make sure that the value of the mode entered is valid |
| call :MYFINDSWITCH %SWMODE% |
| if not "%RET%"=="0" if not "%RETV%"=="1" if not "%RETV%"=="2" goto ERROR_INVALID_MODE |
| |
| rem make sure that the value of the outputfile entered does not have any extension |
| call :MYFINDSWITCH %SWOUTPUT% |
| for /f "tokens=1* delims=." %%I in ("%RETV%") do (set OUTPUTEXT=%%J) |
| if not "%OUTPUTEXT%"=="" goto ERROR_USED_OUTPUTFILENAME_WITH_EXTENSION |
| |
| rem if we have come this far, everything went well, set the valid flag |
| set VALID=1 |
| goto :EOF |
| |
| :ERROR_USED_SAME_SWITCH_TWICE |
| (echo Invalid Usage : use the switch %RET% multiple times) & (call :HELP) & (goto :EOF) |
| |
| :ERROR_USED_BOTH_MODE_AND_TRACELOG |
| (echo Invalid Usage : cannot use both "-%SWMODE%" and "-%SWTRACELOG%" at the same time) & (call :HELP) & (goto :EOF) |
| |
| :ERROR_USED_ARGUMENTS_WITHOUT_SWITCHES |
| call :GETARG 1 |
| echo Invalid Usage : "%RET%" used without any switch |
| call :HELP |
| goto :EOF |
| |
| :ERROR_INVALID_MODE |
| (echo Invalid Usage : Valid values for %SWMODE% are 1 and 2) & (call :HELP) & (goto :EOF) |
| |
| :ERROR_USED_OUTPUTFILENAME_WITH_EXTENSION |
| (echo Invalid Usage : Output filename should not have any extension) & (call :HELP) & (goto :EOF) |
| |
| rem *************** end of procedure VALIDATE |
| |
| rem *************** start of procedure HELP |
| :HELP |
| echo Usage |
| echo "msdtcvtr { -MODE {1 | 2} | -tracelog tracelogfilename } [options]" |
| echo "All switches can be prefixed with either '-' or '/'" |
| echo Parameters: |
| echo "-MODE 1 to view background tracing" |
| echo "-MODE 2 to view tracing generated by ui" |
| echo "-tracelog <file> binary Trace log file name" |
| echo Options: |
| echo "-h OR -? Display Help" |
| echo "-o <filename> Output Filename without extension" |
| echo "-mof <filename> Mof Filename" |
| goto :EOF |
| |
| |
| |
| rem *************** start of procedure DISPLAY_ERROR_MESSAGE |
| :DISPLAY_ERROR_MESSAGE |
| echo Failed to convert the binary trace data to text format. |
| echo Following reasons can cause this to happen: |
| echo 1) The utility TraceFmt.exe is missing |
| echo 2) The file %TRACEFILE% is either missing or corrupted |
| echo 3) The file %MOFFILE% is either missing or corrupted |
| echo The exact error message can be found in the file '%ERRORFILE%' |
| goto :EOF |
| |
| |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| :INIT |
| %TRACE% [proc %0 %*] |
| |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| :VARDEL |
| %TRACE% [proc %0 %*] |
| for /f "tokens=1 delims==" %%I in ('set %1 2^>nul') do set %%I= |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| :PARSECMDLINE |
| %TRACE% [proc %0 %*] |
| if not {%1}=={1} ( |
| (call :VARDEL CMDARG_) |
| (call :VARDEL CMDSW_) |
| (set /a CMDARGCOUNT=0) |
| (set /a CMDSWCOUNT=0) |
| ) |
| set /a RET=0 |
| call :PARSECMDLINE1 %CMDLINE% 1>nul |
| set _MTPLIB_T1= |
| set _LASTARGSWITCH=0 |
| set _LASTARGSWITCHNAME=0 |
| goto :EOF |
| :PARSECMDLINE1 |
| if {%1}=={} goto :EOF |
| set _MTPLIB_T1=%1 |
| set _MTPLIB_T1=%_MTPLIB_T1:"=% |
| set /a RET+=1 |
| shift /1 |
| if "%_MTPLIB_T1:~0,1%"=="/" goto :PARSECMDLINESW |
| if "%_MTPLIB_T1:~0,1%"=="-" goto :PARSECMDLINESW |
| if "%_LASTARGSWITCH%"=="1" ( |
| set CMDSW_%CMDSWCOUNT%=%_LASTARGSWITCHNAME%:%_MTPLIB_T1% |
| set _LASTARGSWITCH=0 |
| goto :PARSECMDLINE1 |
| ) |
| set /a CMDARGCOUNT+=1 |
| set CMDARG_%CMDARGCOUNT%=%_MTPLIB_T1% |
| set _LASTARGSWITCH=0 |
| goto :PARSECMDLINE1 |
| :PARSECMDLINESW |
| set /a CMDSWCOUNT+=1 |
| set CMDSW_%CMDSWCOUNT%=%_MTPLIB_T1% |
| set _LASTARGSWITCH=1 |
| set _LASTARGSWITCHNAME=%_MTPLIB_T1% |
| goto :PARSECMDLINE1 |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| |
| |
| :GETARG |
| %TRACE% [proc %0 %*] |
| set RET= |
| if %1 GTR %CMDARGCOUNT% goto :EOF |
| if %1 EQU 0 goto :EOF |
| if not defined CMDARG_%1 goto :EOF |
| set RET=%%CMDARG_%1%% |
| call :RESOLVE |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| |
| |
| |
| :GETSWITCH |
| %TRACE% [proc %0 %*] |
| (set RET=) & (set RETV=) |
| if %1 GTR %CMDSWCOUNT% goto :EOF |
| if %1 EQU 0 goto :EOF |
| if not defined CMDSW_%1 goto :EOF |
| set RET=%%CMDSW_%1%% |
| call :RESOLVE |
| for /f "tokens=1* delims=:" %%I in ("%RET%") do (set RET=%%I) & (set RETV=%%J) |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| :FINDSWITCH |
| %TRACE% [proc %0 %*] |
| if {%2}=={} (set /a _MTPLIB_T4=1) else (set /a _MTPLIB_T4=%2) |
| :FINDSWITCHLOOP |
| call :GETSWITCH %_MTPLIB_T4% |
| if "%RET%"=="" (set RET=0) & (goto :FINDSWITCHEND) |
| if /i "%RET%"=="%1" (set RET=%_MTPLIB_T4%) & (goto :FINDSWITCHEND) |
| set /a _MTPLIB_T4+=1 |
| goto :FINDSWITCHLOOP |
| :FINDSWITCHEND |
| set _MTPLIB_T4= |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| :MYFINDSWITCH |
| %TRACE% [proc %0 %*] |
| if {%2}=={} (set /a _MTPLIB_T4=1) else (set /a _MTPLIB_T4=%2) |
| :MYFINDSWITCHLOOP |
| call :GETSWITCH %_MTPLIB_T4% |
| if "%RET%"=="" (set RET=0) & (goto :MYFINDSWITCHEND) |
| if /i "%RET:~1%"=="%1" (set RET=%_MTPLIB_T4%) & (goto :MYFINDSWITCHEND) |
| set /a _MTPLIB_T4+=1 |
| goto :MYFINDSWITCHLOOP |
| :MYFINDSWITCHEND |
| set _MTPLIB_T4= |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| |
| :REGSETM |
| %TRACE% [proc %0 %*] |
| for /f "tokens=1* delims==" %%I in ('set %2 2^>nul') do call :REGSET1 HKLM %1 %%I "%%J" |
| goto :EOF |
| :REGSETU |
| %TRACE% [proc %0 %*] |
| for /f "tokens=1* delims==" %%I in ('set %2 2^>nul') do call :REGSET1 HKCU %1 %%I "%%J" |
| goto :EOF |
| :REGSET1 |
| set _MTPLIB_T10=%4 |
| set _MTPLIB_T10=%_MTPLIB_T10:\=\\% |
| reg add %1\Software\MTPScriptContexts\%2\%3=%_MTPLIB_T10% >nul |
| reg update %1\Software\MTPScriptContexts\%2\%3=%_MTPLIB_T10% >nul |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| :REGGETM |
| %TRACE% [proc %0 %*] |
| for /f "delims= tokens=2*" %%I in ('reg query HKLM\Software\MTPScriptContexts\%1\%2 ^|find "REG_SZ"') do call :REGGETM1 %%I "%%J" |
| goto :EOF |
| :REGGETU |
| %TRACE% [proc %0 %*] |
| for /f "delims= tokens=2*" %%I in ('reg query HKCU\Software\MTPScriptContexts\%1\%2 ^|find "REG_SZ"') do call :REGGETM1 %%I "%%J" |
| goto :EOF |
| :REGGETM1 |
| set _MTPLIB_T10=%2 |
| set _MTPLIB_T10=%_MTPLIB_T10:\\=\% |
| set _MTPLIB_T10=%_MTPLIB_T10:"=% |
| set %1=%_MTPLIB_T10% |
| set RET=%_MTPLIB_T10% |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| |
| :REGDELM |
| %TRACE% [proc %0 %*] |
| call :GETTEMPNAME |
| echo y >%RET% |
| reg delete HKLM\Software\MTPScriptContexts\%1\%2 <%RET% >nul |
| del %RET% |
| goto :EOF |
| :REGDELU |
| %TRACE% [proc %0 %*] |
| call :GETTEMPNAME |
| echo y >%RET% |
| reg delete HKCU\Software\MTPScriptContexts\%1\%2 <%RET% >nul |
| del %RET% |
| goto :EOF |
| |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| :SRAND |
| %TRACE% [proc %0 %*] |
| set /a _MTPLIB_NEXTRAND=%1 |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| :RAND |
| %TRACE% [proc %0 %*] |
| if not defined _MTPLIB_NEXTRAND set /a _MTPLIB_NEXTRAND=1 |
| set /a _MTPLIB_NEXTRAND=_MTPLIB_NEXTRAND * 214013 + 2531011 |
| set /a RET=_MTPLIB_NEXTRAND ^>^> 16 ^& 0x7FFF |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| |
| |
| :RESOLVE |
| %TRACE% [proc %0 %*] |
| :RESOLVELOOP |
| if "%RET%"=="" goto :EOF |
| set RET1=%RET% |
| for /f "tokens=*" %%I in ('echo %RET%') do set RET=%%I |
| if not "%RET%"=="%RET1%" goto :RESOLVELOOP |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| :GETINPUTLINE |
| %TRACE% [proc %0 %*] |
| call :GETTEMPNAME |
| set _MTPLIB_T1=%RET% |
| copy con "%_MTPLIB_T1%" >nul |
| for /f "tokens=*" %%I in ('type "%_MTPLIB_T1%"') do set RET=%%I |
| if exist "%_MTPLIB_T1%" del "%_MTPLIB_T1%" |
| set _MTPLIB_T1= |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| :GETSYNCFILE |
| %TRACE% [proc %0 %*] |
| call :GETTEMPNAME |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| :SETSYNCFILE |
| %TRACE% [proc %0 %*] |
| echo . >%1 |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| :DELSYNCFILE |
| %TRACE% [proc %0 %*] |
| if exist %1 del %1 |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| |
| |
| |
| :WAITSYNCFILE |
| %TRACE% [proc %0 %*] |
| if {%2}=={} (set /a RET=60) else (set /a RET=%2) |
| if exist %1 goto :EOF |
| :WAITSYNCFILELOOP |
| sleep 1 |
| set /a RET-=1 |
| if %RET% GTR 0 if not exist %1 goto :WAITSYNCFILELOOP |
| goto :EOF |
| |
| rem ///////////////////////////////////////////////////////////////////////// |
| |
| |
| |
| |
| |
| :GETTEMPNAME |
| %TRACE% [proc %0 %*] |
| if not defined _MTPLIB_NEXTTEMP set /a _MTPLIB_NEXTTEMP=1 |
| if defined TEMP ( |
| (set RET=%TEMP%) |
| ) else if defined TMP ( |
| (set RET=%TMP%) |
| ) else (set RET=%SystemRoot%) |
| :GETTEMPNAMELOOP |
| set /a _MTPLIB_NEXTTEMP=_MTPLIB_NEXTTEMP * 214013 + 2531011 |
| set /a _MTPLIB_T1=_MTPLIB_NEXTTEMP ^>^> 16 ^& 0x7FFF |
| set RET=%RET%\~SH%_MTPLIB_T1%.tmp |
| if exist "%RET%" goto :GETTEMPNAMELOOP |
| set _MTPLIB_T1= |
| goto :EOF |
| |
| rem These must be the FINAL LINES in the script... |
| :DOSEXIT |
| echo This script requires Windows NT |
| |
| rem /////////////////////////////////////////////////////////////////////////COPY |