![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-08-05 02:05 |
共 48,038 主题排行 / 350,123 发帖 / 今日 0 篇 / 48,251 会员排行 |
| DOS批处理 & 脚本技术(批处理室) » 批处理检测进程是否存在, 然后做出选择问题. |
| 可打印版本 2,218 / 14 |
| 第1楼 sweetdreamlan | 发表于 2006-08-28 13:23 |
| 中级用户 发帖 92 积分 244 | |
|
批处理检测进程是否存在, 然后做出选择问题. 想做一个 批处理检测系统的一个进程是否存在的脚本, 如果不存在,就自动关机. 应该会用到IF语句吧, 希望高手指点.
|
|
| 第2楼 kcdsw | 发表于 2006-08-28 13:42 |
| 中级用户 发帖 179 积分 404 | |
|
tasklist
然后剩下的自己想 |
|
| 第3楼 sweetdreamlan | 发表于 2006-08-28 15:21 |
| 中级用户 发帖 92 积分 244 | |
|
这个命令用起来有点难度 能不能做个示范,谢谢
|
|
| 第4楼 sweetdreamlan | 发表于 2006-08-28 15:36 |
| 中级用户 发帖 92 积分 244 | |
|
想了好久 就是写不出来
|
|
| 第5楼 electronixtar | 发表于 2006-08-28 19:22 |
| 铂金会员 发帖 2,672 积分 7,493 | |
|
说明写少了
|
|
| 第6楼 sweetdreamlan | 发表于 2006-08-28 19:53 |
| 中级用户 发帖 92 积分 244 | |
|
哪个高手帮帮忙, 开个头
我用IF 不知道怎么开头 |
|
| 第7楼 sweetdreamlan | 发表于 2006-08-28 20:00 |
| 中级用户 发帖 92 积分 244 | |
|
主要是 IF, 怎么和 tasklist 连起来用
|
|
| 第8楼 vkill | 发表于 2006-08-29 12:54 |
| 金牌会员 发帖 1,744 积分 4,103 来自 甘肃.临泽 | |
|
tasklist >tasklist.txt
rem 进程名如 smss.exe find /i tasklist.txt "进程名" if errorlevel 1 ((del /q tasklist.txt)&(goto end)) if errorlevel 0 ((del /q tasklist.txt)&(echo 有你想要的进程)&pause&exit) :end shutdown -s -t 1 不过这样只有这个bat运行一次检测一次,没有实时监控 [ Last edited by he200377 on 2006-8-29 at 12:58 ] |
|
| 第9楼 sweetdreamlan | 发表于 2006-08-29 16:22 |
| 中级用户 发帖 92 积分 244 | |
|
恩, 非常感谢 我在想下看怎么实施坚控
|
|
| 第10楼 sweetdreamlan | 发表于 2006-08-29 16:44 |
| 中级用户 发帖 92 积分 244 | |
|
OK 了, 用了FOR 语句
|
|
| 第11楼 sweetdreamlan | 发表于 2006-08-29 19:52 |
| 中级用户 发帖 92 积分 244 | |
|
用Explorer.exe 进程测试
tasklist >tasklist.txt find /i tasklist.txt "Explorer.exe" if errorlevel 1 ((del /q tasklist.txt)&(goto end)) if errorlevel 0 ((del /q tasklist.txt)&(echo Explorer.exe)&pause&exit) :end shutdown -s -t 50 上面的脚本, 只是检测一下 不会即实监测. 下面是改过的脚本 用Goto 语句做 监测 :start tasklist >tasklist.txt find /i tasklist.txt "Explorer.exe" if errorlevel 1 ((del /q tasklist.txt)&(goto end)) if errorlevel 0 ((goto start)) :end shutdown -s -t 50 这样一来 如果Explorer.exe 进程,存在, 就是死循环. 直到 Explorer.exe 进程结束, 就执行 关机命令. 但这样有个缺点 CPU 100% 哪位能解决 ... |
|
| 第12楼 vkill | 发表于 2006-08-29 20:13 |
| 金牌会员 发帖 1,744 积分 4,103 来自 甘肃.临泽 | |
|
在结合一个 at.bat 10分钟执行一次,可是还不算实监控
如果楼主想一个进程不被结束,可以考虑用工具给进程加密,结束要密码 |
|
| 第13楼 sweetdreamlan | 发表于 2006-08-30 20:49 |
| 中级用户 发帖 92 积分 244 | |
|
1.bat
_____ at 00:01 start D:\a.bat at 00:02 start D:\a.bat at 00:03 start D:\a.bat at 00:04 start D:\a.bat at 00:05 start D:\a.bat ....... at 24:00 start D:\a.bat __________________ a.bat ____ :start tasklist >tasklist.txt find /i tasklist.txt "Explorer.exe" if errorlevel 1 ((del /q tasklist.txt)&(goto end)) exit :end shutdown -s -t 50 把 a.bat 放D盘 然后运行 1.bat 这样就达到了, 1分钟检测下进程进否存在的条件了 不会让 CPU 到100% 哪位大侠有更高的,请写出来. |
|
| 第14楼 namejm | 发表于 2006-08-30 21:13 |
| 荣誉版主 发帖 1,737 积分 5,226 来自 成都 | |
|
以下代码每隔10分钟检测一次进程列表,如果不存在explorer.exe,则自动关机
楼主这个问题其实属于比较简单的循环问题,以前都有过讨论的,请多用论坛的搜索功能。 相关讨论请看: 如何实现30秒间隔循环执行一个批处理文件?? http://www.cn-dos.net/forum/viewthread.php?tid=22267&fpage=1&highlight=%E5%BE%AA%E7%8E%AF [ Last edited by namejm on 2006-8-30 at 21:20 ] |
|
| 第15楼 luowei14 | 发表于 2007-06-18 14:56 |
| 初级用户 发帖 98 积分 193 | |
|
好帖就得顶。。。。楼主的帖让我领悟了很多东西。。下面这个作品就是拜楼主所赐
每隔20秒自动检测进程列表,自动关闭notepad.exe,也就是记事本程序,如有需要,可以改成某病毒的名称,可以起到监控的作用。。。 @echo off :1 tasklist | find "notepad.exe" >>c:\notepad.luowei if exist c:\notepad.luowei taskkill /f /im notepad.exe ping 127.1 -n 20 >nul 2>nul goto 1 |
|
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |