批处理写的系统文件替换

  1. :: Replacer 2.62 Pre-release  
  2. :: www3.telus.net/_/replacer/  
  3. :: Email: undefined@telus.net  
  4.  
  5. ::系统文件替换  
  6. ::est翻译,整理  
  7. :: 转发于:http://www.cn-dos.net/forum/viewthread.php?tid=23453  
  8.  
  9. @echo off 
  10. title Replacer  
  11. :: Check operating system  
  12. :: 检查操作系统版本  
  13. ver | find "NT" >nul && (  
  14. echo/ ! Windows NT not supported.  
  15. pause >nul  
  16. goto:eof  
  17. )  
  18. setlocal disabledelayedexpansion enableextensions  
  19.  
  20. :: Use components, if they exist  
  21. :: 如果有组建的话则使用组建  
  22. if exist "%~dp0Components\*.exe" (  
  23. set "path=%~dp0Components;%path%" 
  24. title Replacer *  
  25. else (  
  26. set "path=%windir%\system32;%path%" 
  27. )  
  28.  
  29. :: Temporary directory  
  30. :: 临时文件夹  
  31. set "dir=%~dp0.ReplacerTemp" 
  32. :: Use %tmp% for read-only media  
  33. :: 如果是只读存储介质则使用 %tmp%   
  34. if not exist "%dir%" md "%dir%" 2>nul || (  
  35. set "dir=%tmp%\.ReplacerTemp" 
  36. md "%tmp%\.ReplacerTemp" 2>nul  
  37. )  
  38.  
  39. :: Flags used to communicate with other scripts  
  40. :: 和其他脚本通讯的flags  
  41. set flg="%dir%\..\.Flag_SafeToDel" 
  42. set fl2="%dir%\.Flag2_SafeToDel" 
  43. :: Files extracted  
  44. :: 析出的文件  
  45. set vbs="%dir%\Clear_WFP_Message.vbs" 
  46. :: Stores rewritten script  
  47. :: 保存重写脚本  
  48. set "scr=%dir%\.CurrentScript" 
  49. :: Stores undo commands, incase system doesn't boot  
  50. :: 保存撤销命令,用于系统不重启  
  51. set und="%windir%\ReplacerUndo.txt" 
  52. :: Stores deleted file  
  53. :: 保存删除的文件  
  54. set del="%dir%\DeletedFile_SafeToDel" 
  55.  
  56. call:brk Purge  
  57.  
  58. :: The additional VBScript is embedded at the bottom  
  59. :: 附加vbs嵌入在最后  
  60. findstr/rc:"^[        ]" "%~0" >%vbs% 2>nul || (  
  61. echo/ ! Embedded file could not be extracted. Try using the Components package from:  
  62. echo/   http://www3.telus.net/_/replacer/Components.zip  
  63. echo/  
  64. echo/Press any key to quit.  
  65. pause >nul  
  66. call:brk Now  
  67. )  
  68.  
  69. :: Check parameters  
  70. :: 检查参数  
  71. if '%1'=='' (  
  72. goto:sys  
  73. else (  
  74. echo/"%*" | find "?" >nul && (  
  75.   goto:hlp) || (if not '%2'=='' goto:hlp)  
  76. )  
  77.  
  78. :scr Manage scripts  
  79. cls  
  80. title Replacer : %~n1  
  81. echo/Checking script...  
  82. echo/  
  83. call:chk "%~f1" || call:brk  
  84. pushd "%~dp1" 
  85. :: All scripts must contain a certain string to prevent binary files  
  86. :: from accidentally being specified and read as scripts  
  87. :: 所有脚本必须包含一个特定的字符串以避免二进制文件被误认为脚本  
  88. find/i ";; ReplacerScript" "%~f1" >nul 2>&1 || (  
  89.   echo/ ! Invalid Replacer script. It does not contain ";; ReplacerScript".  
  90.   echo/  
  91.   call:brk  
  92. )  
  93. copy/v/y "%~f1" "%scr%" >nul  
  94. :: Get script format and prompt for each optional file  
  95. :: 获得脚本结构,提示每个可选文件  
  96. for /f "usebackq tokens=1,2,3,4 delims=, eol=;" %%a in (  
  97.   "%scr%") do (  
  98.   setlocal  
  99.   call:idt "%%~b" "%%~c" "%%~d" "%%~a" && (  
  100.    call:exm "%%~a" && call:opt "%%~a" 
  101.   )  
  102.   endlocal  
  103. )  
  104. if not exist "%scr%-tmp%" (  
  105.   type nul > "%scr%-tmp" 
  106. )  
  107. copy/v/y "%scr%-tmp" "%scr%" >nul  
  108. :: Count files that will be replaced  
  109. :: 计算有多少个文件被替换  
  110. for /f "tokens=3 delims=:" %%* in (  
  111.   'find/c /v "" "%scr%"') do (  
  112.   if "%%*"==" 0" (  
  113.    echo/ ! No files to replace.  
  114.    echo/  
  115.    call:brk  
  116.   ) else (  
  117.    echo/  
  118.    echo/%%* file^(s^) will be replaced.  
  119.   )  
  120. )  
  121. echo/  
  122. echo/Press any key to start the script.  
  123. pause >nul  
  124. cls  
  125. :: Print and replace each file  
  126. :: 现实、替换每个文件  
  127. call:vbs  
  128. for /f "usebackq tokens=1,2,3,4 delims=, eol=;" %%a in (  
  129.   "%scr%") do (  
  130.   setlocal  
  131.   echo/ * %%~a:  
  132.   :: Tokens are: SysFile,Replacement,Ref#,Optional  
  133.   :: 令牌环为:系统文件,替换源,引用#,可选项  
  134.   call:seq "%%~a" "%%~b" "%%~c" "%%~d" 
  135.   echo/  
  136.   endlocal  
  137. )  
  138. type nul > %flg%  
  139. echo/  
  140. echo/Complete. Reboot to see changes.  
  141. echo/Press any key to quit.  
  142. pause >nul  
  143. del "%scr%" 
  144. del "%scr%-tmp" 
  145. call:brk Now  
  146.  
  147. :sys Get system file  
  148. cls  
  149. set "sys=" 
  150. echo/Drag the ORIGINAL system file to replace into this window.  
  151. echo/Then, press enter to continue.  
  152. echo/Or, type Q to quit.  
  153. call:get sys || goto:sys  
  154. call:quo sys  
  155. if /i %sys%=="Q" (  
  156.   call:brk Now  
  157. )  
  158. :: If only filename provided, scan for closest match  
  159. :: 如果只提供了文件名,则寻找最合适的匹配  
  160. if %sys:\=%==%sys% (  
  161.   if not %sys:.=%==%sys% (  
  162.    call:scn %sys%  
  163.   )  
  164. )  
  165. if defined pth (  
  166.   for %%* in (%sys%) do (  
  167.    set sys="%pth%%%~nx*" 
  168.   )  
  169. )  
  170. call:chk %sys% || (  
  171.   echo/Press any key to continue.  
  172.   pause >nul  
  173.   goto:sys  
  174. )  
  175. :: Check if a script was given as system file  
  176. :: 检查所给的脚本是否为系统文件  
  177. for %%* in (%sys%) do (  
  178.   if /i "%%~x*"==".txt" (  
  179.    find/i ";; ReplacerScript" %%* >nul && (  
  180.     call:scr %%*  
  181.    )  
  182.   )  
  183. )  
  184. call:ver %sys% || goto:sys  
  185.  
  186. :mod Get replacement file  
  187. cls  
  188. set "mod=" 
  189. echo/Drag the REPLACEMENT %nam% into this window.  
  190. if exist %bak% (  
  191.   echo/Or, type RESTORE to restore the backup of %nam%.  
  192. )  
  193. echo/Then, press enter to continue.  
  194. echo/Or, type Q to quit.  
  195. call:get mod || goto:mod  
  196. call:quo mod  
  197. if /i %mod%=="Q" call:brk Now  
  198. if /i %mod%=="RESTORE" (call:rst || goto:mod)  
  199. call:chk %mod% || (  
  200.   echo/Press any key to continue.  
  201.   pause >nul  
  202.   goto:mod  
  203. )  
  204. if /i %mod%==%sys% (  
  205.   echo/ ! A file cannot replace itself.  
  206.   echo/  
  207.   echo/Press any key to continue.  
  208.   pause >nul  
  209. ) && goto:mod  
  210.  
  211. :cnf Confirm operation  
  212. cls  
  213. if %mod%==%bak% (  
  214.   echo/File will be restored.  
  215. else (  
  216.   if exist %bak% (  
  217.    echo/File will not be backed up, backup already exists.  
  218.   ) else (  
  219.    for %%* in (%sys%) do (  
  220.     echo/File will be backed up to:  
  221.     echo/"%%~dpn*.backup" 
  222.    )  
  223.   )  
  224. )  
  225. echo/  
  226. echo/The current file:  
  227. echo/%sys%  
  228. echo/will be replaced with:  
  229. echo/%mod%  
  230. echo/  
  231. echo/Continue? ^(Y/N^)  
  232. call:get cnf || goto:cnf  
  233. call:quo cnf  
  234. if /i not "%cnf:~1,1%"=="Y" call:brk Now  
  235. cls  
  236.  
  237. :vbs Start VBScript  
  238. :: A flag tells the VBScript when to exit, so WFP messages can still  
  239. :: be cleared after Replacer.cmd exits  
  240. :: 一个flag可以告诉vbs何时退出,那么当本批处理退出时 Windows文件保护(WFP)就不会有提示  
  241. if exist %flg% del %flg%  
  242. if not "%atr%"=="non" (  
  243.   start "" /belownormal wscript //b %vbs% %flg% || (  
  244.    echo/VBScript failed:  
  245.    echo/%vbs%  
  246.    echo/  
  247.   )  
  248. )  
  249. if exist "%scr%" exit/b  
  250.  
  251. :rep Replace file  
  252. if exist %und% del/f %und%  
  253. if not exist "%scr%" (  
  254.   echo/ * %nam%:  
  255. )  
  256. :: Overwrite system files with replacement  
  257. :: 把系统文件替换了!  
  258. if /i not %mod%==%bak% (  
  259.   if not exist %bak% (  
  260.    echo/   - Backing up...  
  261.    call:cpy %sys% %bak%  
  262.   )  
  263. )  
  264. :: Not all files are protected  
  265. :: 不是所有的文件都是被保护的  
  266. if not "%atr%"=="non" (  
  267.   if exist %dll% (  
  268.    echo/   - Copying to DllCache...  
  269.    call:cpy %mod% %dll%  
  270.   )  
  271.   if exist %spf% (  
  272.    echo/   - Copying to ServicePackFiles...  
  273.    call:cpy %mod% %spf%  
  274.   )  
  275.   if exist %c86% (  
  276.    echo/   - Compressing to i386 folder...  
  277.    call:cpy %mod% %fil%  
  278.    call:cab %fil% %c86%  
  279.   )  
  280.   if exist %w86% (  
  281.    echo/   - Compressing to Windows i386 folder...  
  282.    call:cpy %mod% %fil%  
  283.    call:cab %fil% %w86%  
  284.   )  
  285.   if exist %d86% (  
  286.    echo/   - Copying to Driver Cache...  
  287.    call:cpy %mod% %d86%  
  288.   )  
  289. )  
  290. if /i %mod%==%bak% (  
  291.   echo/   - Restoring system file...  
  292. else (  
  293.   echo/   - Replacing system file...  
  294. )  
  295. :: Simply renaming files circumvents WFP:  
  296. :: http://virtualplastic.net/html/art_hack.html#winxp  
  297. :: 简单的把WFP文件重命名  
  298. if exist %dlp% del/f %dlp% 2>nul  
  299. ren %sys% %dln% 2>nul || (  
  300.   echo/   ! Overwrite failed.  
  301.   echo/  
  302.   call:brk  
  303. )  
  304. del/f %dlp% 2>nul || (  
  305.   echo/   ! Warning: Temporary file could not be removed:  
  306.   echo/     %dlp%  
  307. )  
  308. call:cpy %mod% %sys%  
  309. if exist "%scr%" (  
  310.   exit/b  
  311. else (  
  312.   type nul > %flg%  
  313. )  
  314.  
  315. :fin Finished  
  316. echo/  
  317. echo/  
  318. echo/Complete. Reboot to see changes.  
  319. echo/Press any key to quit.  
  320. pause >nul  
  321. call:brk Now  
  322.  
  323. goto:eof  
  324.  
  325.  
  326. :get Get input (var)  
  327. echo/  
  328. set/p "%~1= > " || exit/b1  
  329. echo/  
  330. exit/b  
  331.  
  332. :quo Quote variable (var)  
  333. :: An ugly yet reliable method of removing quotes  
  334. :: 一个“丑陋”但是很可靠的删除引号的方法  
  335. call set "quo=%%%1%%" 
  336. set "quo=###%quo%###" 
  337. set "quo=%quo:"###=%"  
  338. set "quo=%quo:###"=%"  
  339. set "quo=%quo:###=%" 
  340. set %1="%quo%" 
  341. set "quo=" 
  342. exit/b  
  343.  
  344. :chk Check file (file)  
  345. if not exist %1 (  
  346.   echo/ ! File does not exist:  
  347.   echo/   %1  
  348.   echo/  
  349.   exit/b1  
  350. )  
  351. if exist %1\ (  
  352.   echo/ ! Folders not allowed:  
  353.   echo/   %1  
  354.   echo/  
  355.   exit/b1  
  356. )  
  357. echo/%1 | find "*" >nul && (  
  358.   echo/ ! Wildcards ^(*^) not allowed.  
  359.   echo/  
  360.   exit/b1  
  361. )  
  362. echo/%1 | find "?" >nul && (  
  363.   echo/ ! Wildcards ^(?^) not allowed.  
  364.   echo/  
  365.   exit/b1  
  366. )  
  367. exit/b0  
  368.  
  369. :ver Verify file (file)  
  370. for %%* in (nam atr bak dll spf  
  371.   cab c86 w86 fln d86 dln) do set "%%*=" 
  372. :: Filename  
  373. :: 文件名  
  374. set "nam=%~nx1" 
  375. :: File path  
  376. :: 文件路径  
  377. set "pth=%~dp1" 
  378. call:\\%~n1 >nul 2>&1 || (  
  379.   :: Whether the file is protected  
  380.   :: 文件是否被保护  
  381.   set "atr=wfp" 
  382. )  
  383. :: Some files have special filenames when used by WFP  
  384. :: 有些文件被WFP保护的时候有特殊的文件名  
  385. if not defined fln set "fln=%~nx1" 
  386. set "pth=%pth%%nam%" 
  387. :: Backup file  
  388. :: 备份文件  
  389. set bak="%~dpn1.backup" 
  390. :: Files to replace 
  391. :: 要替换的文件  
  392. set dll="%windir%\system32\dllcache\%fln%" 
  393. set spf="%windir%\servicepackfiles\i386\%fln%" 
  394. set "cab=%fln%" 
  395. set "cab=%cab:~0,-1%_" 
  396. set c86="%systemdrive%\i386\%cab%" 
  397. set w86="%windir%\i386\%cab%" 
  398. set d86="%windir%\Driver Cache\i386\%fln%" 
  399. :: Temporary copy used when compressing file  
  400. :: 压缩文件时的临时副本  
  401. set fil="%dir%\%~nx1" 
  402. :: Temporary name given to system file  
  403. :: 系统文件的临时名称  
  404. set dln="%~nx1_SafeToDel" 
  405. set dlp="%~f1_SafeToDel" 
  406. exit/b0  
  407.  
  408. :rst Restore backup  
  409. if not exist %bak% (  
  410.   echo/ ! Backup does not exist:  
  411.   echo/   %bak%  
  412.   echo/  
  413.   echo/Press any key to continue.  
  414.   pause >nul  
  415.   exit/b1  
  416. else (  
  417.   set "mod=%bak%" 
  418. )  
  419. exit/b0  
  420.  
  421. :cpy Copy file (source, target)  
  422. if not %2==%sys% (  
  423.   attrib -h -r -s %1  
  424.   if exist %2 (  
  425.    attrib -h -r -s %2  
  426.   )  
  427. )  
  428. copy/v/y %1 %2 >nul 2>&1 || (  
  429.   echo/ ! Copy failed.  
  430.   echo/  
  431.   call:brk  
  432. )  
  433. :: Write to undo file  
  434. :: 写入撤销文件  
  435. if /i not %1==%bak% (  
  436.   if /i not %2==%bak% (  
  437.    >>%und% echo/del %2  
  438.    >>%und% echo/copy %bak% %2  
  439.   )  
  440. )  
  441. exit/b  
  442.  
  443. :cab Compress file (source, target)  
  444. attrib -r -s -h %2  
  445. :: Overwrite compressed backup files (generally in i386 folders)  
  446. :: 覆盖压缩的备份文件(通常在 i386 目录)  
  447. makecab/v1 %1 %2 >nul 2>&1 || (  
  448.   echo/ ! Compress failed.  
  449.   echo/  
  450.   call:brk  
  451. )  
  452. del %fil% 2>nul  
  453. exit/b  
  454.  
  455. :hlp Display help  
  456. echo/Replaces protected system files.  
  457. echo/  
  458. echo/ Usage:  
  459. echo/  %~n0 "ScriptFile" 
  460. echo/  
  461. echo/ Example:  
  462. echo/  %~n0 "C:\Replacer\Script.txt" 
  463. echo/  
  464. echo/ Script syntax:  
  465. echo/  ;; ReplacerScript  
  466. echo/  ; Comment  
  467. echo/  SystemFileName [,ReplacementFile] [,Reference#] [,Optional]  
  468. echo/  
  469. echo/ Script example:  
  470. echo/  ;; ReplacerScript  
  471. echo/  ; Replace Notepad, Calc, Paint  
  472. echo/  notepad.exe,notepad.new  
  473. echo/  calc.exe,files\calc.new  
  474. echo/  mspaint.exe,"C:\Files\paint.new" 
  475. echo/  ; Prompt to optionally restore Notepad from backup  
  476. echo/  notepad.exe,RESTORE,Optional  
  477. echo/  
  478. echo/ See readme.txt for ReferenceNumber details.  
  479. exit/b  
  480.  
  481. :idt Identify script format (last 3 tokens, sys)  
  482. :: Ugly method of determining which tokens are which  
  483. :: 检查对应令牌环的“丑陋”方法  
  484. set "sys=%~4" 
  485. if /i "%~1"=="Restore" (  
  486.   if "%~2" LSS "9" (  
  487.    if "%~2"=="" (  
  488.     set "typ=R--" 
  489.    ) else (  
  490.     if "%~2" GEQ "0" (  
  491.      if /i "%~3"=="Optional" (  
  492.       set "typ=RNO" 
  493.      ) else (  
  494.       if /i "%~3"=="" (  
  495.        set "typ=RN-" 
  496.       )  
  497.      )  
  498.     )  
  499.    )  
  500.   ) else (  
  501.    if /i "%~2"=="Optional" (  
  502.     set "typ=R-O" 
  503.    )  
  504.   )  
  505. else (  
  506.   if "%~1" LSS "9" (  
  507.    if "%~1"=="" (  
  508.     set "typ=---" 
  509.    ) else (  
  510.     if "%~1" GEQ "0" (  
  511.      if /i "%~2"=="Optional" (  
  512.       set "typ=-NO" 
  513.      ) else (  
  514.       if /i "%~2"=="" (  
  515.        set "typ=-N-" 
  516.       )  
  517.      )  
  518.     )  
  519.    )  
  520.   ) else (  
  521.    if /i "%~1"=="Optional" (  
  522.     set "typ=--O" 
  523.    ) else (  
  524.     if "%~2" LSS "9" (  
  525.      if "%~2"=="" (  
  526.       set "typ=M--" 
  527.      ) else (  
  528.       if "%~2" GEQ "0" (  
  529.        if "%~3"=="" (  
  530.         set "typ=MN-" 
  531.        ) else (  
  532.         if /i "%~3"=="Optional" (  
  533.          set "typ=MNO" 
  534.         )  
  535.        )  
  536.       )  
  537.      )  
  538.     ) else (  
  539.      if /i "%~2"=="Optional" (  
  540.       set "typ=M-O" 
  541.      )  
  542.     )  
  543.    )  
  544.   )  
  545. )  
  546. if not defined typ (  
  547.   echo/ ! Format of line unknown.  
  548.   echo/  
  549.   exit/b1  
  550. else (  
  551.   call:\%typ% "%~1" "%~2" "%~3" 
  552. )  
  553. exit/b0  
  554.  
  555. :exm Examine script (sys)  
  556. call:scn "%~1" 
  557. if not exist "%pth%\%~nx1" (  
  558.   echo/ ! System file not found:  
  559.   echo/   "%~1" 
  560.   echo/  
  561.   exit/b1  
  562. )  
  563. if /i not "%mod%"=="Restore" (  
  564.   if not exist "%mod%" (  
  565.    echo/ ! Replacement file not found:  
  566.    echo/   "%mod%" 
  567.    echo/  
  568.    exit/b1  
  569.   )  
  570. )  
  571. if not "%num%"=="" (  
  572.   find/i ":\\%~n1%num%" "%~f0" >nul 2>&1 || (  
  573.    echo/ ! Invalid reference number:  
  574.    echo/   "%~nx1,%num%" 
  575.    echo/  
  576.    exit/b1  
  577.   )  
  578. )  
  579. exit/b0  
  580.  
  581. :opt Handles optional lines in scripts (sys)  
  582. if /i "%opt%"=="Optional" (  
  583.   echo: ? Replace optional file "%~1"? ^(Y/N^)  
  584.   setlocal enabledelayedexpansion  
  585.   call:get var  
  586.   if /i "!var!"=="Y" (  
  587.    endlocal  
  588.    call:fmt "%sys%,%mod%,%num%,%opt%" 
  589.    exit/b  
  590.   ) else (  
  591.    endlocal  
  592.   )  
  593. else (  
  594.   call:fmt "%sys%,%mod%,%num%,%opt%" 
  595.   exit/b1  
  596. )  
  597. exit/b0  
  598.  
  599. :fmt Format script  
  600. :: Fill in tokens if any are missing  
  601. :: 如果有遗漏则填充令牌环  
  602. set "var=%~1" 
  603. set "var=%var:,,=, ,%" 
  604. set "var=%var:,,=, ,%" 
  605. >>"%scr%-tmp" echo/%var%  
  606. exit/b0  
  607.  
  608. :seq Run sequence (4 ordered tokens)  
  609. :: Used when replacing files from script  
  610. :: 当用脚本替换文件时使用  
  611. set "pth=" 
  612. if not "%~3"==" " (  
  613.   call:\\%~n1%~3  
  614. else (  
  615.   call:scn %1  
  616. )  
  617. set "sys=%pth%%~nx1" 
  618. if /i "%~2"=="Restore" (  
  619.   set "mod=%pth%%~n1.backup" 
  620. else (  
  621.   set "mod=%~f2" 
  622. )  
  623. call:quo sys  
  624. call:quo mod  
  625. call:chk %sys% || exit/b  
  626. call:chk %mod% || exit/b  
  627. call:ver %sys% || exit/b  
  628. call:rep  
  629. exit/b0  
  630.  
  631. :scn Scan Folders  
  632. :: Finds the most likely file match when only filename is given  
  633. :: (during scripts or system file input)  
  634. :: 如果只给定了文件名,则查找最合适的匹配(在脚本、系统文件输入的时候)  
  635. set "pth=%~1" 
  636. if not "%pth:\=%" == "%pth%" (  
  637.   set "pth=%~dp1" 
  638. else (  
  639.   set "pth=" 
  640.   call:\\%~n10 2>nul && exit/b0  
  641.   :: More common paths at top 
  642.   :: 通常路径  
  643.   for %%* in (  
  644.    "%windir%" 
  645.    "%windir%\system32" 
  646.    "%windir%\system32\drivers" 
  647.    "%windir%\system" 
  648.    "%programfiles%\Outlook Express" 
  649.    "%programfiles%\Windows Media Player" 
  650.    "%windir%\Resources\Themes\Luna" 
  651.    "%programfiles%\Movie Maker" 
  652.    "%programfiles%\Windows NT" 
  653.    "%windir%\PCHEALTH\HELPCTR\Binaries" 
  654.    "%windir%\Fonts" 
  655.    "%programfiles%\Internet Explorer" 
  656.    "%programfiles%\Internet Explorer\Connection Wizard" 
  657.    "%commonprogramfiles%\Microsoft Shared\MSInfo" 
  658.    "%programfiles%\Windows NT\Accessories" 
  659.    "%programfiles%\Windows NT\Pinball" 
  660.    "%commonprogramfiles%\System" 
  661.    "%windir%\system32\Restore" 
  662.    "%windir%\system32\srchasst" 
  663.    "%windir%\system32\usmt" 
  664.    "%commonprogramfiles%\Microsoft Shared\Speech" 
  665.    "%programfiles%\NetMeeting" 
  666.    "%commonprogramfiles%\System\Mapi\1033" 
  667.    "%commonprogramfiles%\Adobe\Calibration" 
  668.    "%programfiles%\Symantec\LiveUpdate" 
  669.    "%programfiles%\WildTangent\Apps\CDA" 
  670.    "%programfiles%\Stardock\Object Desktop\IconPackager" 
  671.   ) do (  
  672.    if not exist %fl2% (  
  673.     if exist "%%~*\%~nx1" (  
  674.      set "pth=%%~*\" 
  675.      type nul > %fl2%  
  676.     )  
  677.    )  
  678.   )  
  679.   if exist %fl2% del %fl2%  
  680. )  
  681. exit/b0  
  682.  
  683. :brk Exit Replacer ([Purge] [Now])  
  684. :: Clean up and exit  
  685. :: 清理,退出  
  686. if not "%~1"=="Purge" (  
  687.   if not "%~1"=="Now" (  
  688.    echo/  
  689.    echo/Press any key to quit.  
  690.    pause >nul  
  691.   )  
  692. )  
  693. if /i not "%~1"=="Purge" if exist "%scr%" popd  
  694. for %%* in (%vbs% %fil% %flg%  
  695.   %fl2% "%scr%" %del% "%scr%-tmp" %dlp%  
  696. ) do if exist %%* del/f %%* >nul 2>&1  
  697. if /i not "%~1"=="Purge" (  
  698.   if exist "%dir%" rd "%dir%" 2>nul  
  699.   endlocal  
  700.   :: Use a hard exit to prevent other loops from continuing  
  701.   :: 如果有其他循环则硬退出  
  702.   exit  
  703. )  
  704. exit/b0  
  705.  
  706. :: List of special files requiring more (or less) steps  
  707. :: 列出需要更多/更少步骤的特殊文件  
  708. :\\Luna  
  709. set "fln=luna.mst" 
  710. set "atr=wfp" 
  711. exit/b0  
  712. :\\Shellstyle  
  713. if /i not "%pth:Homestead=%"=="%pth%" (  
  714.   set "fln=home_ss.dll" 
  715. )  
  716. if /i not "%pth:Metallic=%"=="%pth%" (  
  717.   set "fln=metal_ss.dll" 
  718. )  
  719. if /i not "%pth:NormalColor=%"=="%pth%" (  
  720.   set "fln=blue_ss.dll" 
  721. )  
  722. if /i not "%pth:\system32\=%"=="%pth%" (  
  723.   set "fln=class_ss.dll" 
  724. )  
  725. set "atr=wfp" 
  726. exit/b0  
  727. :\\Marlett  
  728. set "atr=non" 
  729. exit/b  
  730. :\\Comctl32  
  731. if /i not "%pth%"=="%windir%\system32\" (  
  732.   set "atr=non" 
  733. )  
  734. exit/b  
  735. :\\Commdlg  
  736. if /i not "%pth%"=="%windir%\system\" (  
  737.   set "atr=non" 
  738. )  
  739. exit/b  
  740. :\\Notepad  
  741. if /i not "%pth%"=="%windir%\" (  
  742.   set "atr=non" 
  743. )  
  744. exit/b  
  745. :\\Uxtheme.dll  
  746. set "atr=wfp" 
  747. :\\Comctl320  
  748. set "pth=%windir%\system32\" 
  749. exit/b  
  750. :\\Comctl321  
  751. set "pth=%windir%\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.0.0_x-ww_1382d70a\" 
  752. exit/b  
  753. :\\Comctl322  
  754. set "pth=%windir%\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.10.0_x-ww_f7fb5805\" 
  755. exit/b  
  756. :\\Comctl323  
  757. set "pth=%windir%\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.1331_x-ww_7abf6d02\" 
  758. exit/b  
  759. :\\Comctl324  
  760. set "pth=%windir%\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.1515_x-ww_7bb98b8a\" 
  761. exit/b  
  762. :\\Comctl325  
  763. set "pth=%windir%\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\" 
  764. exit/b  
  765. :\\Commdlg0  
  766. set "pth=%windir%\system\" 
  767. exit/b  
  768. :\\Commdlg1  
  769. set "pth=%windir%\system32\" 
  770. exit/b  
  771. :\\Notepad0  
  772. set "pth=%windir%\" 
  773. exit/b  
  774. :\\Notepad1  
  775. set "pth=%windir%\system32\" 
  776. exit/b  
  777. :\\Shellstyle0  
  778. set "pth=%windir%\system32\" 
  779. exit/b  
  780. :\\Shellstyle1  
  781. set "pth=%windir%\Resources\Themes\Luna\Shell\NormalColor\" 
  782. exit/b  
  783. :\\Shellstyle2  
  784. set "pth="%windir%\Resources\Themes\Luna\Shell\Metallic\"  
  785. exit/b  
  786. :\\Shellstyle3  
  787. set "pth=%windir%\Resources\Themes\Luna\Shell\Homestead\" 
  788. exit/b  
  789.  
  790. :: List of script line formats  
  791. :: 脚本行格式的列表  
  792. :\RNO  
  793. set "mod=Restore" 
  794. set "num=%~2" 
  795. set "opt=%~3" 
  796. exit/b  
  797. :\R-O  
  798. set "mod=Restore" 
  799. set "num=" 
  800. set "opt=%~2" 
  801. exit/b  
  802. :\RN-  
  803. set "mod=Restore" 
  804. set "num=%~2" 
  805. set "opt=" 
  806. exit/b  
  807. :\R--  
  808. set "mod=Restore" 
  809. set "num=" 
  810. set "opt=" 
  811. exit/b  
  812. :\-N-  
  813. set "mod=%sys%" 
  814. set "num=%~1" 
  815. set "opt=" 
  816. exit/b  
  817. :\-NO 
  818. set "mod=%sys%" 
  819. set "num=%~1" 
  820. set "opt=%~2" 
  821. exit/b  
  822. :\--O  
  823. set "mod=%sys%" 
  824. set "num=" 
  825. set "opt=%~1" 
  826. exit/b  
  827. :\M--  
  828. set "mod=%~1" 
  829. set "num=" 
  830. set "opt=" 
  831. exit/b  
  832. :\MN-  
  833. set "mod=%~1" 
  834. set "num=%~2" 
  835. set "opt=" 
  836. exit/b  
  837. :\M-O  
  838. set "mod=%~1" 
  839. set "num=" 
  840. set "opt=%~2" 
  841. exit/b  
  842. :\MNO  
  843. set "mod=%~1" 
  844. set "num=%~2" 
  845. set "opt=%~3" 
  846. exit/b  
  847. :\---  
  848. set "mod=%sys%" 
  849. set "num=" 
  850. set "opt=" 
  851. exit/b  
  852.  
  853. :: Clear_WFP_Message.vbs -- clears the WFP message  
  854. :: 清除WFP消息的脚本  
  855.         ' Clears WFP message  
  856.         ' 清楚WFP消息  
  857.         const win="Windows File Protection" 
  858.         const wi2="Unable To Locate Component" 
  859.         set arg=wscript.arguments  
  860.         if arg.count then 
  861.          flg=arg.item(0)  
  862.          else wscript.echo "Bad parameters." 
  863.           wscript.quit  
  864.         end if  
  865.         set w=wscript.createobject("wscript.shell")  
  866.         set f=wscript.createobject("scripting.filesystemobject")  
  867.         x=999  
  868.         while x > 0  
  869.          if w.appactivate(win) then 
  870.           w.sendkeys "{ESC}" 
  871.           w.sendkeys "{TAB}{ENTER}" 
  872.          end if  
  873.          if w.appactivate(wi2) then 
  874.           w.sendkeys "{ESC}{TAB}{ENTER}" 
  875.          end if  
  876.          if f.fileexists(flg) then 
  877.           x=45  
  878.           f.deletefile(flg)  
  879.          end if  
  880.          wscript.sleep 333  
  881.          x=x-1  
  882.         wend 
原文地址:https://www.cnblogs.com/amylis_chen/p/2650703.html