[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

作品阅读:msdtcvtr.bat

多读,多想,多写是有好处的,在系统里发现这个东东,不明白是做什么的,不建议执行,仅供学习阅读。
  1. @echo off
  2. rem *************** start of 'main'
  3. set DEBUG=0
  4. if "%DEBUG%"=="1" (set TRACE=echo) else (set TRACE=rem)
  5. rem Note that right now there is a bug in tracerpt.exe cause of which you might want to use tracefmt.exe instead.
  6. rem set the value 1 if you want to use tracefmt.exe instead
  7. set USE_TRACE_FMT=1
  8. %TRACE% The value of variable USE_TRACE_FMT is %USE_TRACE_FMT%
  9. rem define variables for each of the switches we support
  10. set SWHELP=h
  11. set SWMODE=mode
  12. set SWTRACELOG=tracelog
  13. set SWMOF=mof
  14. set SWOUTPUT=o
  15. set VALID=0
  16. rem define variables for parameters to be passed to tracerpt
  17. set TRACEDIR=%WINDIR%\system32\msdtc\trace
  18. set TRACEFILE1=%TRACEDIR%\dtctrace.log
  19. set TRACEFILE2=%TRACEDIR%\tracetx.log
  20. set MOFFILE=%TRACEDIR%\msdtctr.mof
  21. set ERRORFILE=%TRACEDIR%\errortrace.txt
  22. set OUTPUTFILE=%TRACEDIR%\trace
  23. rem Parse command line and setup variables
  24. set CMDLINE=%*
  25. %TRACE% About to call PARSECMDLINE with the argument %CMDLINE%
  26. call :PARSECMDLINE 0
  27. rem Validate the command line
  28. %TRACE% About to call the procedure VALIDATE
  29. call :VALIDATE
  30. rem if Vaidation fails, we give up
  31. if "%VALID%"=="0" (
  32. %TRACE% Parameter validation failed, exiting ...
  33. goto :EOF
  34. )
  35. rem depending on the value of the mode, set the tracelogfile
  36. call :MYFINDSWITCH %SWMODE%
  37. if not "%RET%"=="0" (
  38. if "%RETV%"=="1" set TRACEFILE=%TRACEFILE1%
  39. if "%RETV%"=="2" set TRACEFILE=%TRACEFILE2%
  40. )
  41. rem if the tracelog switch was used, set the tracelogfile
  42. call :MYFINDSWITCH %SWTRACELOG%
  43. if not "%RET%"=="0" (
  44. set TRACEFILE=%RETV%
  45. )
  46. rem if the mof switch was used, set the moffile
  47. call :MYFINDSWITCH %SWMOF%
  48. if not "%RET%"=="0" (
  49. set MOFFILE=%RETV%
  50. )
  51. rem if the output switch was used, set the output file
  52. call :MYFINDSWITCH %SWOUTPUT%
  53. if not "%RET%"=="0" (
  54. set OUTPUTFILE=%RETV%
  55. )
  56. %TRACE% TRACEFILE=%TRACEFILE%
  57. %TRACE% MOFFILE=%MOFFILE%
  58. %TRACE% OUTPUTFILE=%OUTPUTFILE%
  59. rem if the specified tracelogfile does not exist, display an error message and give up
  60. if not exist %TRACEFILE% (
  61. echo The tracelogfile %TRACEFILE% does not exist. exiting ...
  62. call :HELP
  63. goto :EOF
  64. )
  65. rem if the specified moffile does not exist, display an error message and give up
  66. if not exist %MOFFILE% (
  67. echo The moffile %MOFFILE% does not exist. exiting ...
  68. call :HELP
  69. goto :EOF
  70. )
  71. rem set a variable for output file with extension
  72. set OUTPUTFILEWITHEXT=%OUTPUTFILE%.csv
  73. %TRACE% The value of variable OUTPUTFILEWITHEXT=%OUTPUTFILEWITHEXT%
  74. rem if the specified outputfile exists, ask if the user is ok with it being over-written.
  75. rem if the user wants to continue, delete the old output file, else give up.
  76. if exist %OUTPUTFILEWITHEXT% (
  77. echo The file %OUTPUTFILEWITHEXT% already exists. You may press Control-C to terminate the batch file. Continuing the batch file will overwrite this file.
  78. Pause
  79. del %OUTPUTFILEWITHEXT% 1>nul 2>nul
  80. )
  81. rem if the old error file exists, delete it
  82. if exist %ERRORFILE% (
  83. del %ERRORFILE% 1>nul 2>nul
  84. %TRACE% Deleted the file %ERRORFILE%
  85. )
  86. rem call the utility with the right arguments
  87. %TRACE% About to call the utility tracerpt.exe ...
  88. if "%USE_TRACE_FMT%"=="0" (goto :USE_TRACEPRT_UTILITY) else (goto :USE_TRACEFMT_UTILITY)
  89. :USE_TRACEPRT_UTILITY
  90. %TRACE% Entered the USE_TRACEPRT_UTILITY block, about to call traceprt
  91. tracerpt %TRACEFILE% -o %OUTPUTFILE% -mof %MOFFILE% > %ERRORFILE% 2>&1
  92. rem if output file does not exist, display an error message and give up
  93. if not exist %OUTPUTFILEWITHEXT% (
  94. %TRACE% The file %OUTPUTFILEWITHEXT% does not exist, therefore exiting ...
  95. call :DISPLAY_ERROR_MESSAGE
  96. goto :EOF
  97. )
  98. notepad %OUTPUTFILEWITHEXT%
  99. goto :EOF
  100. :USE_TRACEFMT_UTILITY
  101. %TRACE% Entered the USE_TRACEFMT_UTILITY block, about to call tracefmt
  102. tracefmt %TRACEFILE% -o %OUTPUTFILEWITHEXT% -tmf %MOFFILE% -nosummary > %ERRORFILE% 2>&1
  103. rem if output file does not exist, display an error message and give up
  104. if not exist %OUTPUTFILEWITHEXT% (
  105. %TRACE% The file %OUTPUTFILEWITHEXT% does not exist, therefore exiting ...
  106. call :DISPLAY_ERROR_MESSAGE
  107. goto :EOF
  108. )
  109. notepad %OUTPUTFILEWITHEXT%
  110. goto :EOF
  111. goto :EOF
  112. rem *************** end of 'main'
  113. rem *************** Procedures begin here ****************************
  114. rem *************** start of procedure VALIDATE
  115. :VALIDATE
  116. set ARG=1
  117. set SWHELPFOUND=0
  118. set SWMODEFOUND=0
  119. set SWTRACELOGFOUND=0
  120. set SWMOFFOUND=0
  121. set SWOUTPUTFOUND=0
  122. set OUTNAMENAME=0
  123. rem If no arguments are used at all, don't perform any other validation, just display help and give up
  124. if %CMDARGCOUNT% EQU 0 if %CMDSWCOUNT% EQU 0 (call :HELP) & (goto :EOF)
  125. rem If not arguments are given, display help
  126. if %CMDARGCOUNT% GTR 0 goto ERROR_USED_ARGUMENTS_WITHOUT_SWITCHES
  127. rem If the switch SWHELP is used anywhere, don't perform any other validation, just display help and give up
  128. call :MYFINDSWITCH %SWHELP%
  129. if not "%RET%"=="0" (call :HELP) & (goto :EOF)
  130. :SWLOOP
  131. if %ARG% GTR %CMDSWCOUNT% goto :SWLOOPEND
  132. call :GETSWITCH %ARG%
  133. set MYSWITCH=%RET:~1%
  134. rem make sure no switch is used twice
  135. if /i "%MYSWITCH%"=="%SWHELP%" (if "%SWHELPFOUND%"=="1" (goto ERROR_USED_SAME_SWITCH_TWICE) else (set SWHELPFOUND=1))
  136. if /i "%MYSWITCH%"=="%SWMODE%" (if "%SWMODEFOUND%"=="1" (goto ERROR_USED_SAME_SWITCH_TWICE) else (set SWMODEFOUND=1))
  137. if /i "%MYSWITCH%"=="%SWTRACELOG%" (if "%SWTRACELOGFOUND%"=="1" (goto ERROR_USED_SAME_SWITCH_TWICE) else (set SWTRACELOGFOUND=1))
  138. if /i "%MYSWITCH%"=="%SWMOF%" (if "%SWMOFFOUND%"=="1" (goto ERROR_USED_SAME_SWITCH_TWICE) else (set SWMOFFOUND=1))
  139. if /i "%MYSWITCH%"=="%SWOUTPUT%" (if "%SWOUTPUTFOUND%"=="1" (goto ERROR_USED_SAME_SWITCH_TWICE) else (set SWOUTPUTFOUND=1))
  140. rem make sure that the switches mode and tracelog are not used simultaneously
  141. if "%SWMODEFOUND%"=="1" if "%SWTRACELOGFOUND%"=="1" goto ERROR_USED_BOTH_MODE_AND_TRACELOG
  142. rem make sure that there is no switch outside our list
  143. if /i not "%MYSWITCH%"=="%SWHELP%" (
  144. if /i not "%MYSWITCH%"=="%SWMODE%" (
  145. if /i not "%MYSWITCH%"=="%SWTRACELOG%" (
  146. if /i not "%MYSWITCH%"=="%SWMOF%" (
  147. if /i not "%MYSWITCH%"=="%SWOUTPUT%" (
  148. (echo Invalid Switch "%RET%") & (call :HELP) & (goto :EOF) )))))
  149. set /a ARG+=1
  150. goto :SWLOOP
  151. :SWLOOPEND
  152. rem make sure that either the switch "-mode" or "-tracelog" was used
  153. if "%SWMODEFOUND%"=="0" if "%SWTRACELOGFOUND%"=="0" (echo Invalid Usage : neither "-%SWMODE%" nor "-%SWTRACELOG%" was specified) & (call :HELP) & (goto :EOF)
  154. rem make sure that the value of the mode entered is valid
  155. call :MYFINDSWITCH %SWMODE%
  156. if not "%RET%"=="0" if not "%RETV%"=="1" if not "%RETV%"=="2" goto ERROR_INVALID_MODE
  157. rem make sure that the value of the outputfile entered does not have any extension
  158. call :MYFINDSWITCH %SWOUTPUT%
  159. for /f "tokens=1* delims=." %%I in ("%RETV%") do (set OUTPUTEXT=%%J)
  160. if not "%OUTPUTEXT%"=="" goto ERROR_USED_OUTPUTFILENAME_WITH_EXTENSION
  161. rem if we have come this far, everything went well, set the valid flag
  162. set VALID=1
  163. goto :EOF
  164. :ERROR_USED_SAME_SWITCH_TWICE
  165. (echo Invalid Usage : use the switch %RET% multiple times) & (call :HELP) & (goto :EOF)
  166. :ERROR_USED_BOTH_MODE_AND_TRACELOG
  167. (echo Invalid Usage : cannot use both "-%SWMODE%" and "-%SWTRACELOG%" at the same time) & (call :HELP) & (goto :EOF)
  168. :ERROR_USED_ARGUMENTS_WITHOUT_SWITCHES
  169. call :GETARG 1
  170. echo Invalid Usage : "%RET%" used without any switch
  171. call :HELP
  172. goto :EOF
  173. :ERROR_INVALID_MODE
  174. (echo Invalid Usage : Valid values for %SWMODE% are 1 and 2) & (call :HELP) & (goto :EOF)
  175. :ERROR_USED_OUTPUTFILENAME_WITH_EXTENSION
  176. (echo Invalid Usage : Output filename should not have any extension) & (call :HELP) & (goto :EOF)
  177. rem *************** end of procedure VALIDATE
  178. rem *************** start of procedure HELP
  179. :HELP
  180. echo Usage
  181. echo "msdtcvtr { -MODE {1 | 2} | -tracelog tracelogfilename } [options]"
  182. echo "All switches can be prefixed with either '-' or '/'"
  183. echo Parameters:
  184. echo "-MODE 1 to view background tracing"
  185. echo "-MODE 2 to view tracing generated by ui"
  186. echo "-tracelog <file> binary Trace log file name"
  187. echo Options:
  188. echo "-h OR -? Display Help"
  189. echo "-o <filename> Output Filename without extension"
  190. echo "-mof <filename> Mof Filename"
  191. goto :EOF
  192. rem *************** end of procedure HELP
  193. rem *************** start of procedure DISPLAY_ERROR_MESSAGE
  194. :DISPLAY_ERROR_MESSAGE
  195. echo Failed to convert the binary trace data to text format.
  196. echo Following reasons can cause this to happen:
  197. echo 1) The utility TraceFmt.exe is missing
  198. echo 2) The file %TRACEFILE% is either missing or corrupted
  199. echo 3) The file %MOFFILE% is either missing or corrupted
  200. echo The exact error message can be found in the file '%ERRORFILE%'
  201. goto :EOF
  202. rem *************** end of procedure DISPLAY_ERROR_MESSAGE
  203. rem /////////////////////////////////////////////////////////////////////////
  204. rem INIT procedure
  205. rem Must be called in local state before other procs are used
  206. rem
  207. :INIT
  208. %TRACE% [proc %0 %*]
  209. goto :EOF
  210. rem /////////////////////////////////////////////////////////////////////////
  211. rem VARDEL procedure
  212. rem Delete multiple variables by prefix
  213. rem
  214. rem Arguments: %1=variable name prefix
  215. rem
  216. :VARDEL
  217. %TRACE% [proc %0 %*]
  218. for /f "tokens=1 delims==" %%I in ('set %1 2^>nul') do set %%I=
  219. goto :EOF
  220. rem /////////////////////////////////////////////////////////////////////////
  221. rem PARSECMDLINE procedure
  222. rem Parse a command line into switches and args
  223. rem
  224. rem Arguments: CMDLINE=command text to parse
  225. rem %1=0 for new parse (def) or 1 to append to existing
  226. rem
  227. rem Returns: CMDARG_n=arguments, CMDSW_n=switches
  228. rem CMDARGCOUNT=arg count, CMDSWCOUNT=switch count
  229. rem RET=total number of args processed
  230. rem
  231. :PARSECMDLINE
  232. %TRACE% [proc %0 %*]
  233. if not {%1}=={1} (
  234. (call :VARDEL CMDARG_)
  235. (call :VARDEL CMDSW_)
  236. (set /a CMDARGCOUNT=0)
  237. (set /a CMDSWCOUNT=0)
  238. )
  239. set /a RET=0
  240. call :PARSECMDLINE1 %CMDLINE% 1>nul
  241. set _MTPLIB_T1=
  242. set _LASTARGSWITCH=0
  243. set _LASTARGSWITCHNAME=0
  244. goto :EOF
  245. :PARSECMDLINE1
  246. if {%1}=={} goto :EOF
  247. set _MTPLIB_T1=%1
  248. set _MTPLIB_T1=%_MTPLIB_T1:"=%
  249. set /a RET+=1
  250. shift /1
  251. if "%_MTPLIB_T1:~0,1%"=="/" goto :PARSECMDLINESW
  252. if "%_MTPLIB_T1:~0,1%"=="-" goto :PARSECMDLINESW
  253. if "%_LASTARGSWITCH%"=="1" (
  254. set CMDSW_%CMDSWCOUNT%=%_LASTARGSWITCHNAME%:%_MTPLIB_T1%
  255. set _LASTARGSWITCH=0
  256. goto :PARSECMDLINE1
  257. )
  258. set /a CMDARGCOUNT+=1
  259. set CMDARG_%CMDARGCOUNT%=%_MTPLIB_T1%
  260. set _LASTARGSWITCH=0
  261. goto :PARSECMDLINE1
  262. :PARSECMDLINESW
  263. set /a CMDSWCOUNT+=1
  264. set CMDSW_%CMDSWCOUNT%=%_MTPLIB_T1%
  265. set _LASTARGSWITCH=1
  266. set _LASTARGSWITCHNAME=%_MTPLIB_T1%
  267. goto :PARSECMDLINE1
  268. goto :EOF
  269. rem /////////////////////////////////////////////////////////////////////////
  270. rem GETARG procedure
  271. rem Get a parsed argument by index
  272. rem
  273. rem Arguments: %1=argument index (1st arg has index 1)
  274. rem
  275. rem Returns: RET=argument text or empty if no argument
  276. rem
  277. :GETARG
  278. %TRACE% [proc %0 %*]
  279. set RET=
  280. if %1 GTR %CMDARGCOUNT% goto :EOF
  281. if %1 EQU 0 goto :EOF
  282. if not defined CMDARG_%1 goto :EOF
  283. set RET=%%CMDARG_%1%%
  284. call :RESOLVE
  285. goto :EOF
  286. rem /////////////////////////////////////////////////////////////////////////
  287. rem GETSWITCH procedure
  288. rem Get a switch argument by index
  289. rem
  290. rem Arguments: %1=switch index (1st switch has index 1)
  291. rem
  292. rem Returns: RET=switch text or empty if none
  293. rem RETV=switch value (after colon char) or empty
  294. rem
  295. :GETSWITCH
  296. %TRACE% [proc %0 %*]
  297. (set RET=) & (set RETV=)
  298. if %1 GTR %CMDSWCOUNT% goto :EOF
  299. if %1 EQU 0 goto :EOF
  300. if not defined CMDSW_%1 goto :EOF
  301. set RET=%%CMDSW_%1%%
  302. call :RESOLVE
  303. for /f "tokens=1* delims=:" %%I in ("%RET%") do (set RET=%%I) & (set RETV=%%J)
  304. goto :EOF
  305. rem /////////////////////////////////////////////////////////////////////////
  306. rem FINDSWITCH procedure
  307. rem Finds the index of the named switch
  308. rem
  309. rem Arguments: %1=switch name
  310. rem %2=search start index (def: 1)
  311. rem
  312. rem Returns: RET=index (0 if not found)
  313. rem RETV=switch value (text after colon)
  314. rem
  315. :FINDSWITCH
  316. %TRACE% [proc %0 %*]
  317. if {%2}=={} (set /a _MTPLIB_T4=1) else (set /a _MTPLIB_T4=%2)
  318. :FINDSWITCHLOOP
  319. call :GETSWITCH %_MTPLIB_T4%
  320. if "%RET%"=="" (set RET=0) & (goto :FINDSWITCHEND)
  321. if /i "%RET%"=="%1" (set RET=%_MTPLIB_T4%) & (goto :FINDSWITCHEND)
  322. set /a _MTPLIB_T4+=1
  323. goto :FINDSWITCHLOOP
  324. :FINDSWITCHEND
  325. set _MTPLIB_T4=
  326. goto :EOF
  327. rem /////////////////////////////////////////////////////////////////////////
  328. rem MYFINDSWITCH procedure
  329. rem Finds the index of the named switch
  330. rem
  331. rem Arguments: %1=switch name without the leading / or -
  332. rem %2=search start index (def: 1)
  333. rem
  334. rem Returns: RET=index (0 if not found)
  335. rem RETV=switch value (text after colon)
  336. rem
  337. :MYFINDSWITCH
  338. %TRACE% [proc %0 %*]
  339. if {%2}=={} (set /a _MTPLIB_T4=1) else (set /a _MTPLIB_T4=%2)
  340. :MYFINDSWITCHLOOP
  341. call :GETSWITCH %_MTPLIB_T4%
  342. if "%RET%"=="" (set RET=0) & (goto :MYFINDSWITCHEND)
  343. if /i "%RET:~1%"=="%1" (set RET=%_MTPLIB_T4%) & (goto :MYFINDSWITCHEND)
  344. set /a _MTPLIB_T4+=1
  345. goto :MYFINDSWITCHLOOP
  346. :MYFINDSWITCHEND
  347. set _MTPLIB_T4=
  348. goto :EOF
  349. rem /////////////////////////////////////////////////////////////////////////
  350. rem REGSETM and REGSETU procedures
  351. rem Set registry values from variables
  352. rem
  353. rem Arguments: %1=reg context (usually script name)
  354. rem %2=variable to save (or prefix to save set of vars)
  355. rem
  356. :REGSETM
  357. %TRACE% [proc %0 %*]
  358. for /f "tokens=1* delims==" %%I in ('set %2 2^>nul') do call :REGSET1 HKLM %1 %%I "%%J"
  359. goto :EOF
  360. :REGSETU
  361. %TRACE% [proc %0 %*]
  362. for /f "tokens=1* delims==" %%I in ('set %2 2^>nul') do call :REGSET1 HKCU %1 %%I "%%J"
  363. goto :EOF
  364. :REGSET1
  365. set _MTPLIB_T10=%4
  366. set _MTPLIB_T10=%_MTPLIB_T10:\=\\%
  367. reg add %1\Software\MTPScriptContexts\%2\%3=%_MTPLIB_T10% >nul
  368. reg update %1\Software\MTPScriptContexts\%2\%3=%_MTPLIB_T10% >nul
  369. goto :EOF
  370. rem /////////////////////////////////////////////////////////////////////////
  371. rem REGGETM and REGGETU procedures
  372. rem Get registry value or values to variables
  373. rem
  374. rem Arguments: %1=reg context (usually script name)
  375. rem %2=variable to restore (def: restore entire context)
  376. rem
  377. rem Returns: RET=value of last variable loaded
  378. rem
  379. rem WARNING: The "delims" value in the FOR commands below is a TAB
  380. rem character, followed by a space. If this file is edited by
  381. rem an editor which converts tabs to spaces, this procedure
  382. rem will break!!!!!
  383. rem
  384. :REGGETM
  385. %TRACE% [proc %0 %*]
  386. for /f "delims= tokens=2*" %%I in ('reg query HKLM\Software\MTPScriptContexts\%1\%2 ^|find "REG_SZ"') do call :REGGETM1 %%I "%%J"
  387. goto :EOF
  388. :REGGETU
  389. %TRACE% [proc %0 %*]
  390. for /f "delims= tokens=2*" %%I in ('reg query HKCU\Software\MTPScriptContexts\%1\%2 ^|find "REG_SZ"') do call :REGGETM1 %%I "%%J"
  391. goto :EOF
  392. :REGGETM1
  393. set _MTPLIB_T10=%2
  394. set _MTPLIB_T10=%_MTPLIB_T10:\\=\%
  395. set _MTPLIB_T10=%_MTPLIB_T10:"=%
  396. set %1=%_MTPLIB_T10%
  397. set RET=%_MTPLIB_T10%
  398. goto :EOF
  399. rem /////////////////////////////////////////////////////////////////////////
  400. rem REGDELM and REGDELU procedures
  401. rem Delete registry values
  402. rem
  403. rem Arguments: %1=reg context (usually script name)
  404. rem %2=variable to delete (def: delete entire context)
  405. rem
  406. :REGDELM
  407. %TRACE% [proc %0 %*]
  408. call :GETTEMPNAME
  409. echo y >%RET%
  410. reg delete HKLM\Software\MTPScriptContexts\%1\%2 <%RET% >nul
  411. del %RET%
  412. goto :EOF
  413. :REGDELU
  414. %TRACE% [proc %0 %*]
  415. call :GETTEMPNAME
  416. echo y >%RET%
  417. reg delete HKCU\Software\MTPScriptContexts\%1\%2 <%RET% >nul
  418. del %RET%
  419. goto :EOF
  420. rem /////////////////////////////////////////////////////////////////////////
  421. rem SRAND procedure
  422. rem Seed the random number generator
  423. rem
  424. rem Arguments: %1=new seed value
  425. rem
  426. :SRAND
  427. %TRACE% [proc %0 %*]
  428. set /a _MTPLIB_NEXTRAND=%1
  429. goto :EOF
  430. rem /////////////////////////////////////////////////////////////////////////
  431. rem RAND procedure
  432. rem Get next random number (0 to 32767)
  433. rem
  434. rem Returns: RET=next random number
  435. rem
  436. :RAND
  437. %TRACE% [proc %0 %*]
  438. if not defined _MTPLIB_NEXTRAND set /a _MTPLIB_NEXTRAND=1
  439. set /a _MTPLIB_NEXTRAND=_MTPLIB_NEXTRAND * 214013 + 2531011
  440. set /a RET=_MTPLIB_NEXTRAND ^>^> 16 ^& 0x7FFF
  441. goto :EOF
  442. rem /////////////////////////////////////////////////////////////////////////
  443. rem RESOLVE procedure
  444. rem Fully resolve all indirect variable references in RET variable
  445. rem
  446. rem Arguments: RET=value to resolve
  447. rem
  448. rem Returns: RET=as passed in, with references resolved
  449. rem
  450. :RESOLVE
  451. %TRACE% [proc %0 %*]
  452. :RESOLVELOOP
  453. if "%RET%"=="" goto :EOF
  454. set RET1=%RET%
  455. for /f "tokens=*" %%I in ('echo %RET%') do set RET=%%I
  456. if not "%RET%"=="%RET1%" goto :RESOLVELOOP
  457. goto :EOF
  458. rem /////////////////////////////////////////////////////////////////////////
  459. rem GETINPUTLINE procedure
  460. rem Get a single line of keyboard input
  461. rem
  462. rem Returns: RET=Entered line
  463. rem
  464. :GETINPUTLINE
  465. %TRACE% [proc %0 %*]
  466. call :GETTEMPNAME
  467. set _MTPLIB_T1=%RET%
  468. copy con "%_MTPLIB_T1%" >nul
  469. for /f "tokens=*" %%I in ('type "%_MTPLIB_T1%"') do set RET=%%I
  470. if exist "%_MTPLIB_T1%" del "%_MTPLIB_T1%"
  471. set _MTPLIB_T1=
  472. goto :EOF
  473. rem /////////////////////////////////////////////////////////////////////////
  474. rem GETSYNCFILE procedure
  475. rem Get a sync file name (file will not exist)
  476. rem
  477. rem Returns: RET=Name of sync file to use
  478. rem
  479. :GETSYNCFILE
  480. %TRACE% [proc %0 %*]
  481. call :GETTEMPNAME
  482. goto :EOF
  483. rem /////////////////////////////////////////////////////////////////////////
  484. rem SETSYNCFILE procedure
  485. rem Flag sync event (creates the file)
  486. rem
  487. rem Arguments: %1=sync filename to flag
  488. rem
  489. :SETSYNCFILE
  490. %TRACE% [proc %0 %*]
  491. echo . >%1
  492. goto :EOF
  493. rem /////////////////////////////////////////////////////////////////////////
  494. rem DELSYNCFILE procedure
  495. rem Delete sync file
  496. rem
  497. rem Arguments: %1=sync filename
  498. rem
  499. :DELSYNCFILE
  500. %TRACE% [proc %0 %*]
  501. if exist %1 del %1
  502. goto :EOF
  503. rem /////////////////////////////////////////////////////////////////////////
  504. rem WAITSYNCFILE
  505. rem Wait for sync file to flag
  506. rem
  507. rem Arguments: %1=sync filename
  508. rem %2=timeout in seconds (def: 60)
  509. rem
  510. rem Returns: RET=Timeout remaining, or 0 if timeout
  511. rem
  512. :WAITSYNCFILE
  513. %TRACE% [proc %0 %*]
  514. if {%2}=={} (set /a RET=60) else (set /a RET=%2)
  515. if exist %1 goto :EOF
  516. :WAITSYNCFILELOOP
  517. sleep 1
  518. set /a RET-=1
  519. if %RET% GTR 0 if not exist %1 goto :WAITSYNCFILELOOP
  520. goto :EOF
  521. rem /////////////////////////////////////////////////////////////////////////
  522. rem GETTEMPNAME procedure
  523. rem Create a temporary file name
  524. rem
  525. rem Returns: RET=Temporary file name
  526. rem
  527. :GETTEMPNAME
  528. %TRACE% [proc %0 %*]
  529. if not defined _MTPLIB_NEXTTEMP set /a _MTPLIB_NEXTTEMP=1
  530. if defined TEMP (
  531. (set RET=%TEMP%)
  532. ) else if defined TMP (
  533. (set RET=%TMP%)
  534. ) else (set RET=%SystemRoot%)
  535. :GETTEMPNAMELOOP
  536. set /a _MTPLIB_NEXTTEMP=_MTPLIB_NEXTTEMP * 214013 + 2531011
  537. set /a _MTPLIB_T1=_MTPLIB_NEXTTEMP ^>^> 16 ^& 0x7FFF
  538. set RET=%RET%\~SH%_MTPLIB_T1%.tmp
  539. if exist "%RET%" goto :GETTEMPNAMELOOP
  540. set _MTPLIB_T1=
  541. goto :EOF
  542. rem These must be the FINAL LINES in the script...
  543. :DOSEXIT
  544. echo This script requires Windows NT
  545. rem /////////////////////////////////////////////////////////////////////////
复制代码
寂寞是黑白的,但黑白不是寂寞,是永恒。BAT 需要的不是可能,而是智慧。

返回列表