中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-07-15 01:28
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » --- -- 结束除主要进程 以外的进程 ? 查看 2,824 回复 15
楼 主 --- -- 结束除主要进程 以外的进程 ? 发表于 2007-04-19 04:38 ·  中国 湖北 武汉 电信
中级用户
★★
积分 313
发帖 162
注册 2007-04-02 06:45
19年会员
UID 83693
性别 男
状态 离线
--- -- 我想 结束除主要进程 以外的进程,如下,可是有问题,请高手指教 !

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 发表于 2007-04-19 05:04 ·  中国 安徽 芜湖 电信
高级用户
★★★
积分 866
发帖 415
注册 2005-12-04 11:19
20年会员
UID 46459
状态 离线
@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
欢迎你到批处理爱好者联盟QQ群:18023953
3 发表于 2007-04-19 05:29 ·  中国 湖北 武汉 电信
中级用户
★★
积分 313
发帖 162
注册 2007-04-02 06:45
19年会员
UID 83693
性别 男
状态 离线
--- -- ??
附件
未命名.bmp
4 发表于 2007-04-19 05:36 ·  中国 湖北 武汉 电信
中级用户
★★
积分 313
发帖 162
注册 2007-04-02 06:45
19年会员
UID 83693
性别 男
状态 离线
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 发表于 2007-04-21 06:40 ·  中国 湖北 武汉 电信
中级用户
★★
积分 313
发帖 162
注册 2007-04-02 06:45
19年会员
UID 83693
性别 男
状态 离线
--- -- 兄弟们未解啊 ?
6 发表于 2007-04-21 06:45 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
积分 2,564
发帖 1,127
注册 2006-12-25 22:57
19年会员
UID 74552
性别 男
状态 离线
仔细检查你代码
7 发表于 2007-04-21 08:53 ·  中国 湖北 武汉 电信
中级用户
★★
积分 313
发帖 162
注册 2007-04-02 06:45
19年会员
UID 83693
性别 男
状态 离线
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 发表于 2007-04-21 09:12 ·  中国 湖北 武汉 电信
中级用户
★★
积分 313
发帖 162
注册 2007-04-02 06:45
19年会员
UID 83693
性别 男
状态 离线
错了 if /i "%%i"==都改为 if /i not "%%i"==
9 发表于 2007-04-21 10:01 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
积分 2,564
发帖 1,127
注册 2006-12-25 22:57
19年会员
UID 74552
性别 男
状态 离线
你将那个delims=这个去掉,采到制表符了
10 发表于 2007-04-22 07:44 ·  中国 湖北 武汉 电信
中级用户
★★
积分 313
发帖 162
注册 2007-04-02 06:45
19年会员
UID 83693
性别 男
状态 离线
--- --

--- -- (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 发表于 2007-04-22 07:49 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
积分 2,564
发帖 1,127
注册 2006-12-25 22:57
19年会员
UID 74552
性别 男
状态 离线
按你要求


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
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
htysm +8 2007-04-22 08:19
12 发表于 2007-04-22 08:19 ·  中国 安徽 芜湖 电信
高级用户
★★★
积分 866
发帖 415
注册 2005-12-04 11:19
20年会员
UID 46459
状态 离线
LS的,精彩。
欢迎你到批处理爱好者联盟QQ群:18023953
13 发表于 2007-04-22 08:23 ·  中国 湖北 武汉 电信
中级用户
★★
积分 313
发帖 162
注册 2007-04-02 06:45
19年会员
UID 83693
性别 男
状态 离线
--- -- 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 发表于 2007-04-22 08:40 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
积分 2,564
发帖 1,127
注册 2006-12-25 22:57
19年会员
UID 74552
性别 男
状态 离线
这些问题你可以仔细观察下,我没有实际试过,不过一定是静态列表
15 发表于 2007-04-22 08:59 ·  中国 广东 广州 电信
中级用户
★★
积分 259
发帖 112
注册 2006-09-18 04:55
19年会员
UID 62928
性别 男
状态 离线
呵呵..挺有意思的!
论坛跳转: