Sign in to follow this  
Followers 0
helldragon

Ending A Process Which Is Not Responding

15 posts in this topic

when you press alt ctrl delete to end a non-responsive process... is there a way to check and do that in autoit?e

Share this post


Link to post
Share on other sites



when you press alt ctrl delete to end a non-responsive process... is there a way to check and do that in autoit?e

Hi,

try this:

Opt("WinTitleMatchMode", 4)
#include <GUIConstants.au3>
#include <Process.au3>

$GUI = GUICreate("Exit Programm", 233, 251, 192, 125)
;Group
$options_G = GUICtrlCreateGroup("Options", 8, 40, 217, 201)
;RadioButton
$taskkill_R = GUICtrlCreateRadio("Taskkill", 16, 64, 80, 17)
$winClose_R = GUICtrlCreateRadio("WinClose", 16, 88, 80, 17)
$winKill_R = GUICtrlCreateRadio("WinKill", 16, 112, 80, 17)
$processClose_R = GUICtrlCreateRadio("ProcessClose", 16, 136, 80, 17)
$pid_R = GUICtrlCreateRadio("ProcessID", 126, 112, 80, 17)
;Label
$status_L = GUICtrlCreateLabel("Ready...", 16, 216, 203, 17, $SS_SUNKEN)
$headline_L = GUICtrlCreateLabel("Exit Program", 16, 8, 211, 25)
$program_L = GUICtrlCreateLabel("Choose Program", 16, 160, 203, 17, $SS_SUNKEN)
;Button
$Go_B = GUICtrlCreateButton("GO", 126, 64, 89, 30)
;ComboBox
$processCombo_C = GUICtrlCreateCombo("", 16, 184, 201, 21)

GUICtrlSetColor($headline_L, "0xff0000")
GUICtrlSetColor($program_L, "0xff0000")
GUICtrlSetFont($headline_L, 14, 400, "", "Arial")
GUICtrlSetState($processCombo_C, $GUI_FOCUS)
GUISetState(@SW_SHOW)

GUICtrlSetState($taskkill_R, $GUI_CHECKED)

_processCombo()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Go_B
            If GUICtrlRead($taskkill_R) = $GUI_CHECKED Then _taskkill()
            If GUICtrlRead($winClose_R) = $GUI_CHECKED Then _winClose()
            If GUICtrlRead($winKill_R) = $GUI_CHECKED Then _winKill()
            If GUICtrlRead($processClose_R) = $GUI_CHECKED Then _processClose()
            If GUICtrlRead($pid_R) = $GUI_CHECKED Then _killByPID()
        Case $msg = $taskkill_R Or $msg = $processClose_R
            _processCombo()
        Case $msg = $winKill_R Or $msg = $winClose_R
            _winListCombo()
        Case Else
        ;;;;;;;
    EndSelect
WEnd

Func _taskkill()
    $rc = _RunDOS("start taskkill /F /IM " & GUICtrlRead($processCombo_C) & " /T")
    GUICtrlSetData($status_L, "Process " & GUICtrlRead($processCombo_C) & " killed")
    Sleep(2500)
    GUICtrlSetData($status_L, "Ready...")
EndFunc  ;==>_taskkill

Func _winClose()
    If WinExists(GUICtrlRead($processCombo_C)) Then
        WinClose(GUICtrlRead($processCombo_C))
    Else
        GUICtrlSetData($status_L, "Window doesn't exist")
        Sleep(2500)
        GUICtrlSetData($status_L, "Ready...")
    EndIf
EndFunc  ;==>_winClose

Func _winKill()
    If WinExists(GUICtrlRead($processCombo_C)) Then
        WinKill(GUICtrlRead($processCombo_C))
    Else
        GUICtrlSetData($status_L, "Window doesn't exist")
        Sleep(2500)
        GUICtrlSetData($status_L, "Ready...")
    EndIf
EndFunc  ;==>_winKill

Func _processClose()
    If ProcessExists(GUICtrlRead($processCombo_C)) Then
        ProcessClose(GUICtrlRead($processCombo_C))
    Else
        GUICtrlSetData($status_L, "Process doesn't exist")
        Sleep(2500)
        GUICtrlSetData($status_L, "Ready...")
    EndIf
EndFunc  ;==>_processClose

Func _killByPID()
    If _ProcessGetName(GUICtrlRead($processCombo_C)) <> '' Then
        $rc = _RunDOS("start taskkill /PID " & GUICtrlRead($processCombo_C) & " /T")
        GUICtrlSetData($status_L, "ProcessID " & GUICtrlRead($processCombo_C) & " - (" & _ProcessGetName(GUICtrlRead($processCombo_C)) & ")" & " killed")
        Sleep(2500)
        GUICtrlSetData($status_L, "Ready...")
    Else
        GUICtrlSetData($status_L, "ProcessID doesn't exist")
        Sleep(2500)
        GUICtrlSetData($status_L, "Ready...")
    EndIf
EndFunc  ;==>_killByPID

Func _processCombo()
    Dim $processArray = ProcessList()
    For $i = 1 To $processArray[0][0]
        GUICtrlSetData($processCombo_C, $processArray[$i][0])
    Next
EndFunc  ;==>_processCombo

Func _winListCombo()
    Dim $windowArray = WinList()
    For $i = 1 To $windowArray[0][0]
    ; Only display visble windows that have a title
        If $windowArray[$i][0] <> "" Then;AND IsVisible($var[$i][1]) Then
            GUICtrlSetData($processCombo_C, $windowArray[$i][0])
        EndIf
    Next
EndFunc  ;==>_winListCombo

Hope that helps ...

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

mmm yeah doesnt work for me... case and select error...

Share this post


Link to post
Share on other sites

mmm yeah doesnt work for me... case and select error...

HI,

:think: what did you do? Works for me.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

mm

Line 70 (File "C:\program files\autoit3\include\process.au3:):

case 0x00000040

Error: "Case" statement with no matching "select" statement

Share this post


Link to post
Share on other sites

mm

Line 70 (File "C:\program files\autoit3\include\process.au3:):

case 0x00000040

Error: "Case" statement with no matching "select" statement

HI,

are you using the beta of autoit? You need beta!

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

meger i would suggest posting that script everytime sum1 asks how to kill a process :think: just give processclose("asdf") to them :(

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

meger i would suggest posting that script everytime sum1 asks how to kill a process :think: just give processclose("asdf") to them :(

Hi,

yeah you're right. But although the script isn't really good, it shows that there are more possibilities than processclose(). :)

Nevertheless, I won't post it anymore. Just thought it could help the guy. :">

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

woops forgot the not part on that would :think:

Share this post


Link to post
Share on other sites

where do i get this Beta?

Share this post


Link to post
Share on other sites

ok well does nobody know how to watch a process, to see if it is responsive or not? and if not how do i close it... WITHOUT ME BEING AT THE COMPUTER OR DOING ANYTHING

Share this post


Link to post
Share on other sites

bump

Share this post


Link to post
Share on other sites

well u could possibly get the title its always like (Not Responding) so if that ever happens u could just do a processclose

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Here's a definite method for finding if an application is hung, I've wrapped it in a small UDF for you:

If _NotResponding("TITLE HERE", "TEXT HERE[OPTIONAL]", 1) Then; The last parameter indicates whether you want to close the hung app or not.
    MsgBox(0,"", "Hung Application, closing app now.")
Else
    MsgBox(0,"", "Application running as intended.")
EndIf

Func _NotResponding($title, $text, $closeIfHung = 0)
    $hWnd = WinGetHandle($title, $text)
    If $hWnd == "" Then
        MsgBox(0,"Error","Could not find window")
        Exit
    EndIf
    $retArr = DllCall("user32.dll", "int", "IsHungAppWindow", "hwnd", $hWnd)
    If @error == 0 Then
        If $retArr[0] == 1 Then
            If $closeIfHung Then
                ProcessClose(WinGetProcess($title, $text))
            EndIf
            Return 1
        EndIf
    Else
        Return 0
    EndIf
EndFunc

Edit: Hooray! 200th post!

Edited by neogia

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0