![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-29 08:55 |
47,816 topics / 349,916 posts / today 0 new / 48,265 members |
| DOS批处理 & 脚本技术(批处理室) » --- -- End all processes except the main ones ? |
| Printable Version 3,069 / 15 |
| Floor1 ooaf | Posted 2007-04-19 04:38 |
| 中级用户 Posts 162 Credits 313 | |
|
--- -- I want to end all processes except the main ones, like below, but there's a problem. Please give me some guidance, experts!
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 |
|
| Floor2 htysm | Posted 2007-04-19 05:04 |
| 高级用户 Posts 415 Credits 866 | |
| Floor3 ooaf | Posted 2007-04-19 05:29 |
| 中级用户 Posts 162 Credits 313 | |
|
Attachments 未命名.bmp (80.48 KiB) |
|
| Floor4 ooaf | Posted 2007-04-19 05:36 |
| 中级用户 Posts 162 Credits 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 --- -- Is there something wrong with this structure itself? -- - eg: the problem of not services.exe== smss.exe !! Then taskkill /im services.exe /t (actually, I want to use pskill to end processes), |
|
| Floor5 ooaf | Posted 2007-04-21 06:40 |
| 中级用户 Posts 162 Credits 313 | |
|
--- -- Brothers, still no solution?
|
|
| Floor6 everest79 | Posted 2007-04-21 06:45 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
Check your code carefully
|
|
| Floor7 ooaf | Posted 2007-04-21 08:53 |
| 中级用户 Posts 162 Credits 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 This one also errors out!! Please advise! |
|
| Floor8 ooaf | Posted 2007-04-21 09:12 |
| 中级用户 Posts 162 Credits 313 | |
|
Wrong, change all the if /i "%%i"== to if /i not "%%i"==
|
|
| Floor9 everest79 | Posted 2007-04-21 10:01 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
Remove that delims= part, it's capturing tabs
|
|
| Floor10 ooaf | Posted 2007-04-22 07:44 |
| 中级用户 Posts 162 Credits 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 Where the error is: for example, if the process name obtained by 'wmic process get name' is services.exe, when processing the if statement, it becomes if /i not services.exe ==smss.exe taskkill /im services.exe /t, then in the next loop if /i not services.exe ==csrss.exe taskkill /im services.exe /t …… As a result, it can't preserve smss.exe,csrss.exe,winlogon.exe,services.exe,lsass.exe, svchost.exe,Explorer.exe (on the condition that I'm using 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 Where the error is: Again taking services.exe as an example, when processing the if statement, I think it should be handled like this: 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 It should pass through the filtering of the if statements one by one, but in reality it only processes the first if statement: if /i not services.exe==smss.exe then it executes taskkill /f /im services.exe right away! I don't understand! --- -- (3) Another idea is to use 'wmic process get name' to list the processes, then find smss.exe,csrss.exe,winlogon.exe,services.exe,lsass.exe,svchost.exe,Explorer.exe and remove them, leaving the processes that should be ended. In one sentence, filtering. Not sure whether that's feasible? (I don't know how to filter) Please advise, experts, or if there is any other method that's fine too, many thanks!! |
|
| Floor11 everest79 | Posted 2007-04-22 07:49 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
According to your requirement
|
|
| Floor12 htysm | Posted 2007-04-22 08:19 |
| 高级用户 Posts 415 Credits 866 | |
|
The poster above, brilliant.
|
|
| Floor13 ooaf | Posted 2007-04-22 08:23 |
| 中级用户 Posts 162 Credits 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 It works, thanks! I also want to ask one more question. If I make a batch file using 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 to end processes, even cmd.exe gets ended, and there is no interpreter anymore. Will the commands after that still run? attrib -s -h d:\* /s pause Also, will taskkill.exe itself get ended? Is the process list obtained by 'wmic process get name' a list at one particular moment, i.e. a static list, or will it change as processes are added and removed, assuming during the loop above (before it finishes), for example if another program is opened, will that program be ended too? |
|
| Floor14 everest79 | Posted 2007-04-22 08:40 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
You can observe these questions carefully yourself. I haven't actually tried it, but it must be a static list
|
|
| Floor15 kennyfan | Posted 2007-04-22 08:59 |
| 中级用户 Posts 112 Credits 259 | |
|
Hehe.. pretty interesting!
|
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |