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

[文本处理] 批处理怎样判断文本,高于这个数值或者小于这个,执行命令?

通过这个命令
tasklist /v>123.txt
得到 123.txt文本内容如下


图像名                       PID 会话名           会话#       内存使用  状态            用户名                                                 CPU 时间 窗口标题                                                               
========================= ====== ================ ======== ============ =============== ================================================== ============ ========================================================================
System Idle Process            0 Console                 0         28 K Running         NT AUTHORITY\SYSTEM                                    14:09:56 暂缺                                                                    
System                         4 Console                 0        304 K Running         NT AUTHORITY\SYSTEM                                     0:01:20 暂缺                                                                    
smss.exe                     460 Console                 0        404 K Running         NT AUTHORITY\SYSTEM                                     0:00:00 暂缺                                                                    
csrss.exe                    972 Console                 0      8,220 K Running         NT AUTHORITY\SYSTEM                                     0:00:45 暂缺                                                                    
winlogon.exe                1012 Console                 0     11,216 K Running         NT AUTHORITY\SYSTEM                                     0:00:01 NetDDE Agent                                                            
services.exe                1056 Console                 0      9,716 K Running         NT AUTHORITY\SYSTEM                                     0:00:14 暂缺                                                                    
lsass.exe                   1068 Console                 0      1,364 K Running         NT AUTHORITY\SYSTEM                                     0:00:11 暂缺                                                                    
svchost.exe                 1244 Console                 0      5,500 K Running         NT AUTHORITY\SYSTEM                                     0:00:00 暂缺                                                                    
svchost.exe                 1292 Console                 0      4,216 K Running         NT AUTHORITY\NETWORK SERVICE                            0:00:03 暂缺                                                                    
svchost.exe                 1324 Console                 0     22,584 K Running         NT AUTHORITY\SYSTEM                                     0:00:07 暂缺                                                                    
svchost.exe                 1436 Console                 0      3,244 K Running         NT AUTHORITY\LOCAL SERVICE                              0:00:00 暂缺                                                                    
spoolsv.exe                 1804 Console                 0      4,936 K Running         NT AUTHORITY\SYSTEM                                     0:00:00 暂缺                                                                    
acs.exe                     1884 Console                 0      9,896 K Running         NT AUTHORITY\SYSTEM                                     0:00:00 暂缺                                                                    
AlipaySecSvc.exe            1912 Console                 0      4,776 K Running         NT AUTHORITY\SYSTEM                                     0:00:00 暂缺                                                                    
winvnc4.exe                 2020 Console                 0     198,068 K Running         NT AUTHORITY\SYSTEM                                     0:00:00 winvnc::IPC_Interface                                                   
wscntfy.exe                 1532 Console                 0      2,624 K Running         IDC-4C0559B01D7\zdq                                     0:00:00 暂缺


然后通过搜索提取  某exe的行,,,,第5列,,,第5列是 进程的内存使用情况  ....比如已经提取出来EXE的内存使用情况是   198,068
每次提取 进程使用情况的值,,,,然后进行判断,,,  如果某EXE内存使用情况低于100,000  或者低于11,216  就使用某DOS命令    高于100,000 或者11,216就退出,,,,
请高手们   出几个列子啊









另外再请教一个判断,,,检测指定判断当前目录的   某TXT的 KB大小,,,,   如果KB大小    小于多少KB  就执行 DOS命令    大于就退出
另外再请教一个判断,,,检测指定判断当前目录的   某TXT的 KB大小,,,,   如果KB大小    小于多少KB  就执行 DOS命令    大于就退出
另外再请教一个判断,,,检测指定判断当前目录的   某TXT的 KB大小,,,,   如果KB大小    小于多少KB  就执行 DOS命令    大于就退出
~!!!!!!!!!

这个是我刚学批处理时做的第一个批处理监控进程,你自己改一下。。。
  1. @echo off
  2. mode con:cols=60 lines=18
  3. title 结束除指定外的所有非法进程
  4. color 17
  5. :head
  6. @echo.
  7. @echo.
  8. @echo.
  9. @echo.
  10. @echo           输入1开始结束除指定外的所有非法进程
  11. @echo.
  12. @echo           输入2开始循环运行结束除指定外的所有非法进程
  13. @echo.
  14. @echo           输入3退出本次批处理所要执行的任务
  15. @echo.
  16. @echo.
  17. @echo.
  18. @echo.
  19. @set /p C= 请输入数字按回车键确认:
  20. @if %C%==1 goto start
  21. @if %C%==2 goto test
  22. @if %C%==3 goto sound
  23. @echo.
  24. @echo  输入有误,请重新输入...
  25. @goto :head
  26. :sound
  27. exit
  28. :start
  29. c:
  30. cd C:\Documents and Settings\Administrator\Local Settings\Temp
  31. @echo 要保留的系统进程>nul
  32. @echo System>>1.txt
  33. @echo cmd.exe>>1.txt
  34. @echo=========================================>>1.txt
  35. @echo 进程为会话管理子系统用以初始化系统变量,ms-dos驱动名称类似lpt1以及com,调用win32壳子系统和运行在windows登陆过程。>nul
  36. @echo smss.exe>>1.txt
  37. @echo 客户端服务子系统,用以控制windows图形相关子系统。>nul
  38. @echo csrss.exe>>1.txt
  39. @echo windows nt用户登陆程序。>nul
  40. @echo winlogon.exe>>1.txt
  41. @echo 用于管理windows服务系统进程。>nul
  42. @echo services.exe>>1.txt
  43. @echo 本地安全权限服务控制windows安全机制。>nul
  44. @echo lsass.exe>>1.txt
  45. @echo service host process是一个标准的动态连接库主机处理服务。>nul
  46. @echo svchost.exe>>1.txt
  47. @echo 输入控制图标用于更改类似国家设置、键盘类型和日期格式。>nul
  48. @echo internat.exe>>1.txt
  49. @echo console ime ime输入法控制台软件。>nul
  50. @echo conime.exe>>1.txt
  51. @echo 是微软的虚拟磁盘共享的程序>nul
  52. @echo iscsiexe>>1.txt.exe>>1.txt
  53. @echo host process是一个标准的动态连接库主机处理服务。>nul
  54. @echo services.exe>>1.txt
  55. @echo 一个合法的系统进程,请切勿结束>nul
  56. @echo wmiprvse.exe>>1.txt
  57. @echo windows program manager或者windows explorer用于控制windows图形shell,包括开始菜单、任务栏,桌面和文件管理。>nul  
  58. @echo explorer.exe>>1.txt
  59. @echo Explorer.exe>>1.txt
  60. @echo microsoft internet explorer浏览器用于浏览网页。>nul
  61. @echo IEXPLORE.EXE>>1.txt
  62. @echo notepad字符编辑器用于打开文档。在windows中附带。>nul
  63. @echo notepad.exe>>1.txt
  64. @echo 任子行监控插件>nul
  65. @echo dismanager.exe>>1.txt
  66. @echo waterframe.exe>>1.txt
  67. @echo TerminalManager.exe>>1.txt
  68. @echo Terminal.exe>>1.txt
  69. @echo 网维大师>nul
  70. @echo BarClientView.exe>>1.txt
  71. @echo ProcessSafe.exe>>1.txt
  72. @echo 驱动防火墙>nul
  73. @echo DrvAnti.exe>>1.txt
  74. @echo 冰点还原>nul
  75. @echo DF5Serv.exe>>1.txt
  76. @echo FrzState2k.exe>>1.txt
  77. @echo Pubwin2007网吧记费管理程序>nul
  78. @echo PubwinClient.exe>>1.txt
  79. @echo 万象网吧记费管理程序>nul
  80. @echo Clsmn.exe>>1.txt
  81. @echo 360安全卫士>nul
  82. @echo 360tray.exe>>1.txt
  83. @echo 360Safe.exe>>1.txt
  84. @echo QQ聊天工具>nul
  85. @echo QQ.exe>>1.txt
  86. @echo 网络游戏\大话西游>nul
  87. @echo xy2.exe>>1.txt
  88. @echo 讯雷5>nul
  89. @echo Thunder5.exe>>1.txt
  90. @echo 世界之窗浏览器>nul
  91. @echo TheWorld.exe>>1.txt
  92. @echo=========================================>>1.txt
  93. tasklist>>2.txt
  94. for /f "eol== tokens=1 delims= " %%i in (2.txt) do echo %%i>>3.txt
  95. del 2.txt
  96. findstr /v /g:1.txt 3.txt >>4.txt
  97. del 1.txt 3.txt
  98. for /f "delims=" %%a in (4.txt) do taskkill /im %%a /f >nul 2>nul
  99. del 4.txt
  100. exit
  101. :test
  102. color 1a
  103. c:
  104. cd C:\Documents and Settings\Administrator\Local Settings\Temp
  105. @echo 查看当前进程>nul
  106. @echo 要保留的系统进程>nul
  107. @echo System>>1.txt
  108. @echo cmd.exe>>1.txt
  109. @echo=========================================>>1.txt
  110. @echo smss.exe>>1.txt
  111. @echo csrss.exe>>1.txt
  112. @echo winlogon.exe>>1.txt
  113. @echo services.exe>>1.txt
  114. @echo lsass.exe>>1.txt
  115. @echo svchost.exe>>1.txt
  116. @echo internat.exe>>1.txt
  117. @echo conime.exe>>1.txt
  118. @echo iscsiexe>>1.txt.exe>>1.txt
  119. @echo services.exe>>1.txt
  120. @echo wmiprvse.exe>>1.txt
  121. @echo explorer.exe>>1.txt
  122. @echo Explorer.exe>>1.txt
  123. @echo IEXPLORE.EXE>>1.txt
  124. @echo notepad.exe>>1.txt
  125. @echo dismanager.exe>>1.txt
  126. @echo waterframe.exe>>1.txt
  127. @echo TerminalManager.exe>>1.txt
  128. @echo Terminal.exe>>1.txt
  129. @echo BarClientView.exe>>1.txt
  130. @echo ProcessSafe.exe>>1.txt
  131. @echo DrvAnti.exe>>1.txt
  132. @echo DF5Serv.exe>>1.txt
  133. @echo FrzState2k.exe>>1.txt
  134. @echo PubwinClient.exe>>1.txt
  135. @echo Clsmn.exe>>1.txt
  136. @echo 360tray.exe>>1.txt
  137. @echo 360Safe.exe>>1.txt
  138. @echo QQ.exe>>1.txt
  139. @echo xy2.exe>>1.txt
  140. @echo Thunder5.exe>>1.txt
  141. @echo TheWorld.exe>>1.txt
  142. @echo=========================================>>1.txt
  143. tasklist>>2.txt
  144. for /f "eol== tokens=1 delims= " %%i in (2.txt) do echo %%i>>3.txt
  145. del 2.txt
  146. findstr /v /g:1.txt 3.txt >>4.txt
  147. del 1.txt 3.txt
  148. for /f "delims=" %%a in (4.txt) do taskkill /im %%a /f >nul 2>nul
  149. del 4.txt
  150. @cls
  151. @echo.
  152. @echo.
  153. @echo.
  154. @echo           正在循环运行结束除指定外的所有非法进程...
  155. goto test
复制代码

TOP

回复 2# ufwuwlgah


    好象和这个没关系吧
~!!!!!!!!!

TOP

  1. @echo off
  2. set "process=winlogon.exe"
  3. for /f "delims=" %%a in ('tasklist /v /fo csv^|findstr /i "%process%"') do (
  4.   call :11 %%a  
  5. )
  6. goto :eof
  7. :11
  8. set "m=%~5"
  9. set "m=%m: k=%"
  10. set "m=%m:,=%"
  11. if %m% lss 100000 echo %~5&pause
复制代码
1

评分人数

TOP

回复 4# apang


    万分感谢
~!!!!!!!!!

TOP

@echo off
setlocal enableDelayedExpansion
for /f "tokens=*" %%i in ('findstr /i "console" 123.txt') do (
        set str=%%i&set "str=!str:*Console=!"
        for /f "tokens=2" %%j in ("!str!") do (
                set str=%%j&set "str=!str:,=!"
                if !str! leq 11216 echo "start 某条命令"
                if !str! geq 11216 echo "kill 某个进程"
        )
)

TOP

回复 4# apang


    好象这个IF命令只可以比较3个字母的   大小    怎么可以比较3个字母以上的  大小值
~!!!!!!!!!

TOP

仅对你
  1. @echo off
  2. set "process=winlogon.exe"
  3. for /f "delims=" %%i in ('tasklist /nh /fo csv /FI "IMAGENAME eq %process%" /FI "MEMUSAGE lt 10000" 2^>nul') do (
  4.     FOR %%j in (%%i) do set "M=%%~j"
  5. )
  6. if defined M (echo %process% 内存使用 %M%) else exit
  7. pause
复制代码

TOP

返回列表