dexto Posted June 1, 2009 Share Posted June 1, 2009 (edited) This is a code that kills all threads on a given process one by one (kills a process even if the process can't be killed the usual method) Edit Note: Original problem fixed $PIDtoKill=ProcessExists ('calc.exe') $objWMIService = ObjGet("winmgmts:\root\cimv2") $procToKill=$objWMIService.ExecQuery ("Select * from win32_process where processid = "&$PIDtoKill) For $procToKillThread In $procToKill ConsoleWrite($procToKillThread.Terminate&@CRLF) Next Edited June 1, 2009 by dexto Link to comment Share on other sites More sharing options...
dexto Posted June 1, 2009 Author Share Posted June 1, 2009 While i'm at it here is my new function example: expandcollapse popupfor $i=1 to 5 run(@SystemDir&'\calc.exe') Next msgbox(0,'ProcessKill()',"Now lets kill all of them") Func ProcessKill($ProcessKill_in);PID or the name of the process If IsNumber($ProcessKill_in) Then $ProcessKill_PID = $ProcessKill_in Else $ProcessKill_all = ProcessList($ProcessKill_in) If @error Then Return 0 $ProcessKill_trackEach = 0 For $ProcessKill_each = 1 To $ProcessKill_all[0][0] $ProcessKill_trackEach += ProcessKill($ProcessKill_all[$ProcessKill_each][1]) Next If $ProcessKill_trackEach == $ProcessKill_all[0][0] Then Return 1 Else Return 0 EndIf EndIf $ProcessKill_PIDtoKill = ProcessExists($ProcessKill_PID) If $ProcessKill_PIDtoKill == 0 Then Return 0 EndIf ProcessClose($ProcessKill_PIDtoKill) Sleep(300) If ProcessExists($ProcessKill_PIDtoKill) == 0 Then Return 1 EndIf $ProcessKill_objWMIService = ObjGet("winmgmts:\root\cimv2") $ProcessKill_procToKill = $ProcessKill_objWMIService.ExecQuery("Select * from win32_process where processid = " & $ProcessKill_PIDtoKill) $ProcessKill_track = 0 For $ProcessKill_procToKillThread In $ProcessKill_procToKill $ProcessKill_track += ConsoleWrite($ProcessKill_procToKillThread.Terminate & @CRLF) Next If $ProcessKill_track > 0 Then Return 0 EndIf Return 1 EndFunc ;==>ProcessKill ConsoleWrite(processkill('calc.exe')&@CRLF) Link to comment Share on other sites More sharing options...
Mobius Posted June 1, 2009 Share Posted June 1, 2009 (edited) Nice functional code dude, but you really should have posted this in the example scripts forum....unless you have some problem with it???oh i see u now... nice post bump exercise. *yawn* Edited June 1, 2009 by Mobius Link to comment Share on other sites More sharing options...
dexto Posted June 1, 2009 Author Share Posted June 1, 2009 (edited) i had originaly since i fixed it i figured some of the guys would still want to see it. Edited June 1, 2009 by dexto Link to comment Share on other sites More sharing options...
dexto Posted June 1, 2009 Author Share Posted June 1, 2009 Suggestions and comments are always welcome anyway. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now