![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-08-29 09:43 |
共 47,816 主题排行 / 349,916 发帖 / 今日 0 篇 / 48,265 会员排行 |
| DOS批处理 & 脚本技术(批处理室) » --- -- 结束除主要进程 以外的进程 ? |
| 可打印版本 3,074 / 15 |
| 第1楼 ooaf | 发表于 2007-04-19 04:38 |
| 中级用户 发帖 162 积分 313 | |
|
--- -- 结束除主要进程 以外的进程 ? --- -- 我想 结束除主要进程 以外的进程,如下,可是有问题,请高手指教 !
for %%i in ('wmic process get name') do ( for /f %%b in (smss.exe,csrss.exe,winlogon.exe,services.exe,lsass.exe,svchost.exe,Explorer.exe) do if /i not "%%i"=="%%b" taskkill /f /im %%i) pause |
|
| 第2楼 htysm | 发表于 2007-04-19 05:04 |
| 高级用户 发帖 415 积分 866 | |
|
@echo off
for /f "skip=1 delims=" %%i in ('wmic process get name') do ( for %%b in (smss.exe,csrss.exe,winlogon.exe,services.exe,lsass.exe, svchost.exe,Explorer.exe) do if /i not %%i== %%b taskkill /im %%i /T ) pause |
|
| 第3楼 ooaf | 发表于 2007-04-19 05:29 |
| 中级用户 发帖 162 积分 313 | |
|
--- -- ??
附件 未命名.bmp (80.48 KiB) |
|
| 第4楼 ooaf | 发表于 2007-04-19 05:36 |
| 中级用户 发帖 162 积分 313 | |
|
for /f "skip=1 delims=" %%i in ('wmic process get name') do (
for %%b in (smss.exe,csrss.exe,winlogon.exe,services.exe,lsass.exe, svchost.exe,Explorer.exe) do if /i not %%i== %%b taskkill /im %%i /T ) pause --- -- 是不是这个 结构本身就有问题 ? -- - eg: not services.exe== smss.exe 的问题 !! 然后 taskkill /im services.exe /t (实际中,我想用pskill 结束进程的 ), |
|
| 第5楼 ooaf | 发表于 2007-04-21 06:40 |
| 中级用户 发帖 162 积分 313 | |
|
--- -- 兄弟们未解啊 ?
|
|
| 第6楼 everest79 | 发表于 2007-04-21 06:45 |
| 金牌会员 发帖 1,127 积分 2,564 | |
|
仔细检查你代码
|
|
| 第7楼 ooaf | 发表于 2007-04-21 08:53 |
| 中级用户 发帖 162 积分 313 | |
|
for /f "skip=3 delims=" %%i in ('wmic process get name') do (
for %%b in (smss.exe,csrss.exe,winlogon.exe,services.exe,lsass.exe, svchost.exe,Explorer.exe) do if /i not %%i==%%b taskkill /im %%i /t ) pause for /f "skip=3 delims=" %%i in ('wmic process get name') do ( if /i "%%i"==smss.exe if /i "%%i"==csrss.exe if /i "%% i"==winlogon.exe if /i "%%i"==services.exe if /i "%%i"==lsass.exe if /i "%%i"==svchost.exe if /i "%%i"==Explorer.exe taskkill /f /im "%%i" ) pause 这个也出错啊 !! 请指教 ! |
|
| 第8楼 ooaf | 发表于 2007-04-21 09:12 |
| 中级用户 发帖 162 积分 313 | |
|
错了 if /i "%%i"==都改为 if /i not "%%i"==
|
|
| 第9楼 everest79 | 发表于 2007-04-21 10:01 |
| 金牌会员 发帖 1,127 积分 2,564 | |
|
你将那个delims=这个去掉,采到制表符了
|
|
| 第10楼 ooaf | 发表于 2007-04-22 07:44 |
| 中级用户 发帖 162 积分 313 | |
|
--- --
--- -- (1) for /f "skip=3 " %%i in ('wmic process get name') do ( for %%b in (smss.exe,csrss.exe,winlogon.exe,services.exe,lsass.exe, svchost.exe,Explorer.exe) do if /i not %%i==%%b taskkill /im %%i /t ) pause 错误处: 比如 'wmic process get name'得到的进程名是 services.exe , 处理 if 句 if /i not services.exe ==smss.exe taskkill /im services.exe /t ,然后再循环 if /i not services.exe ==csrss.exe taskkill /im services.exe /t …… 结果并不能保留 smss.exe,csrss.exe,winlogon.exe,services.exe,lsass.exe, svchost.exe,Explorer.exe (条件是我用pskill ) --- -- (2) for /f "skip=3" %%i in ('wmic process get name') do ( if /i not "%% i"==smss.exe if /i not "%%i"==csrss.exe if /i not "%%i"==winlogon.exe if /i not "%%i"==services.exe if /i not "%%i"==lsass.exe if /i not "%% i"==svchost.exe if /i not "%%i"==Explorer.exe taskkill /f /im "%%i") pause 错误处: 再以services.exe 为例, 处理 if 句 ,我认为会如下处理的: if /i not services.exe ==smss.exe if /i not services.exe ==csrss.exe if /i not services.exe==winlogon.exe …… if /i not services.exe==Explorer.exe taskkill /f /im services.exe 依次 经过 if 的过滤, 而实际上 只处理第一个 if 句 : if /i not services.exe==smss.exe 就执行 taskkill /f /im services.exe 了 ! 不解啊! --- -- (3) 还有一个思路就是 用 'wmic process get name' 列出进程列表 ,再找出 smss.exe,csrss.exe,winlogon.exe,services.exe,lsass.exe,svchost.exe,Explorer.exe 删除他们后留下要结束的进程, 一句话就是过滤, 不知可不可行 ? (我不会过滤) 请高手指教, 或者有其他方法也行 ,多谢 !! |
|
| 第11楼 everest79 | 发表于 2007-04-22 07:49 |
| 金牌会员 发帖 1,127 积分 2,564 | |
|
按你要求
|
|
| 第12楼 htysm | 发表于 2007-04-22 08:19 |
| 高级用户 发帖 415 积分 866 | |
|
LS的,精彩。
|
|
| 第13楼 ooaf | 发表于 2007-04-22 08:23 |
| 中级用户 发帖 162 积分 313 | |
|
--- -- for /f "skip=3" %%i in ('wmic process get name^|findstr /v /i "smss.exe csrss.exe
winlogon.exe services.exe lsass.exe svchost.exe explorer.exe"') do echo %i >>af.txt pause 可行,谢了! 我还想问个问题, 就是用 做一个 批处理, for /f "skip=3" %%i in ('wmic process get name^|findstr /v /i "smss.exe csrss.exe winlogon.exe services.exe lsass.exe svchost.exe explorer.exe"') do taskkill /f /imi %i 结束进程, 连 cmd.exe 都结束了,没有了解释器, 这以后的命令 还会运行吗 ? attrib -s -h d:\* /s pause 还有就是 taskkill.exe 会不会被结束 ? 'wmic process get name 得到的进程列表 是某一时刻 的列表 即 静态列表 ,还是 会随进程的增减 而变化 ,条件是 上面的循环过程中(还没结束 ) ,比如再打开一个程序, 这个程序会被结束吗 ? |
|
| 第14楼 everest79 | 发表于 2007-04-22 08:40 |
| 金牌会员 发帖 1,127 积分 2,564 | |
|
这些问题你可以仔细观察下,我没有实际试过,不过一定是静态列表
|
|
| 第15楼 kennyfan | 发表于 2007-04-22 08:59 |
| 中级用户 发帖 112 积分 259 | |
|
呵呵..挺有意思的!
|
|
| 1 2 下一页 |
|
[ 联系联盟系统管理团队 -
中国DOS联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |