PDA

View Full Version : Batch-File Blues..


c4p0ne
01-30-05, 07:48 AM
Here's my dilemma. In order to understand it better let me just tell you what I want the result of the task to be:

Kill all processes EXCEPT the ones I tell you not to kill.

I wan't to use the pslist & pskill (both by sysinternals.com) utilities to accomplish this task but using a batch file to automate the procedure. Basically I want to somehow parse the output of pslist.exe and feed it to the pskill.exe utility in such a way that I can terminate all the processes in memory EXCEPT a few predefined ones such as "svchost.exe" obviously. Get it? Is this possible to do in a simple batch file or will this shiznit require some more thought?

Please let me know if you can help. Much appreciated.

TonyT
01-30-05, 11:53 AM
Killing tasks is already built into XP using the command: taskkill.
example:
taskkill /f /im explorer.exe
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskkill.mspx

ColdFusion
01-30-05, 01:14 PM
Yeah, but he is still then stuck with the problem of getting the tasks in the first place.

I'm not good with batch files, but heres what i would do. Have the batch file run pslist.exe>>pslist.txt. Have the batch file to some how go through each line and compare it to a list of proccess not to be killed. If the proccess isnt listed, then run taskill taskkill /f /im %x and continue to loop through the list.

TonyT
01-30-05, 04:51 PM
Yeah, but he is still then stuck with the problem of getting the tasks in the first place.

I'm not good with batch files, but heres what i would do. Have the batch file run pslist.exe>>pslist.txt. Have the batch file to some how go through each line and compare it to a list of proccess not to be killed. If the proccess isnt listed, then run taskill taskkill /f /im %x and continue to loop through the list.
Well, per his post, getting the tasks in the first place does not matter at all, as he did not say exactly what specific tasks he wants to kill. Without knowing that, one would then need to use pause in the bat file and one would have to read the tasklist output and then choose what to kill. Or one must know in advance of running it just what tasks will be killed, which is not stated in his post.

Does he know in advance what processes are running? Ones to be killed?

ColdFusion
02-02-05, 06:34 PM
Yeah tonyt he does.

I wan't to use the pslist & pskill

Pslist is a proccess lister. He would need to list the proccess and then kill the ones he specifically says he doesnt want killed. He would almost need to create some sort of loop to loop through every line of the pslist output and compare it to the list of 'what not to be killed'. Defenatly need norm for this one lol ...

Norm
02-02-05, 08:29 PM
Defenatly need norm for this one lol ...I'm waiting for the answer too lol

A tad beyond my ability to parse a file and compare to a list. Something I would have to research and develop, and no time for it right now.

btw - taskill is only available in XP Pro, otherwise it can be found in the resource kit.

ColdFusion
02-03-05, 04:43 PM
well i'm a mirc junkie so ill write the script in mIRC and maybe someone can make some sense out of it in the BAT format.


alias killproc {
var %nokill = explorer.exe, svchost.exe, spoolsv.exe, lsass.exe, services.exe, wilogon.exe, crss.exe smss.exe
if ($exists(pslist.exe)) {
/run cmd /c pslist.exe>>pslist.txt
pause 3000
goto next
}
:next
if ($exists(pskill.exe)) {
var %x = 0
while (%x <= $lines(pslist.txt)) {
if %nokill isin $read(pskill.txt,%x) { inc %x | break }
.run cmd /c pskill.exe $read(pslist.txt,%x)
inc %x
}
}
}

c4p0ne
02-14-05, 07:28 AM
Thanks for the reply's guys.. I've temporarily solved this problem with the single following command (not using pslist/pskill):


taskkill /F /FI "PID ne 4" /FI "PID ne 0" /FI "IMAGENAME ne services.exe" /FI "IMAGENAME ne svchost.exe" /FI "IMAGENAME ne winlogon.exe" /FI "IMAGENAME ne lsass.exe" /FI "IMAGENAME ne spoolsv.exe" /FI "IMAGENAME ne kav.exe" /FI "IMAGENAME ne kavsvc.exe" /FI "IMAGENAME ne explorer.exe" /FI "IMAGENAME ne smss.exe" /FI "IMAGENAME ne frzstate2k.exe" /FI "IMAGENAME ne df5serv.exe" /FI "IMAGENAME ne nvsvc32.exe" /FI "IMAGENAME ne r_server.exe" /FI "IMAGENAME ne csrss.exe" /FI "IMAGENAME ne svcnost.exe" /FI "IMAGENAME ne ctfmon.exe" /FI "IMAGENAME ne reader_sl.exe" /FI "IMAGENAME ne wmiprvse.exe" /IM *

It was a biatch to figure it perfectly, but so far this works and does not interfere with viatal services.