Board logo

标题: --- -- 结束除主要进程 以外的进程 ? [打印本页]

作者: ooaf     时间: 2007-4-19 04:38    标题: --- -- 结束除主要进程 以外的进程 ?

--- -- 我想 结束除主要进程 以外的进程,如下,可是有问题,请高手指教 ! 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

作者: htysm     时间: 2007-4-19 05:04
@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

作者: ooaf     时间: 2007-4-19 05:29
--- -- ??
附件 1: 未命名.bmp (2007-4-19 05:29, 80.48 K,下载次数: 5)



作者: ooaf     时间: 2007-4-19 05:36
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 结束进程的 ),

作者: ooaf     时间: 2007-4-21 06:40
--- -- 兄弟们未解啊 ?

作者: everest79     时间: 2007-4-21 06:45
仔细检查你代码

作者: ooaf     时间: 2007-4-21 08:53
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 这个也出错啊 !! 请指教 !

作者: ooaf     时间: 2007-4-21 09:12
错了 if /i "%%i"==都改为 if /i not "%%i"==

作者: everest79     时间: 2007-4-21 10:01
你将那个delims=这个去掉,采到制表符了

作者: ooaf     时间: 2007-4-22 07:44
--- -- --- -- (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 删除他们后留下要结束的进程, 一句话就是过滤, 不知可不可行 ? (我不会过滤) 请高手指教, 或者有其他方法也行 ,多谢 !!

作者: everest79     时间: 2007-4-22 07:49
按你要求
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

作者: htysm     时间: 2007-4-22 08:19
LS的,精彩。

作者: ooaf     时间: 2007-4-22 08:23
--- -- 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 得到的进程列表 是某一时刻 的列表 即 静态列表 ,还是 会随进程的增减 而变化 ,条件是 上面的循环过程中(还没结束 ) ,比如再打开一个程序, 这个程序会被结束吗 ?

作者: everest79     时间: 2007-4-22 08:40
这些问题你可以仔细观察下,我没有实际试过,不过一定是静态列表

作者: kennyfan     时间: 2007-4-22 08:59
呵呵..挺有意思的!

作者: waynebeat     时间: 2007-4-22 09:24
Originally posted by everest79 at 2007-4-22 07:49: 按你要求 [code] 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 ...
很精彩,虽然,也想到了findstr,但感觉用errorlevel判断……没有everest79兄来的巧妙