Jump to content
Sign in to follow this  
Ontosy

process exit

Recommended Posts

Ontosy

when i use processclose with Foobar2000 i have a error on restart in the configuration file.

Do it is possibile to send a generic message to a application to exit instead to brute force close?

Share this post


Link to post
Share on other sites
Ontosy

WinClose("foobar") ;)

It would be nice if you could also use it with the file name.

Share this post


Link to post
Share on other sites
Melba23

Ontosy,

guinness has posted something which gets the GUI handle from the process name - have a search and see if you can find it. :)

M23

Edit:

I found this from SmOke_N in the Snippets Wiki: ;)

#include <array.au3>
Local $a1, $a2, $a3, $a4
$a1 = _WinGetHandleByPID(232)
$a2 = _WinGetHandleByPID("scite.exe", -1)
$a3 = _WinGetHandleByPID("scite.exe", 0)
$a4 = _WinGetHandleByPID("scite.exe", 1)
_ArrayDisplay($a1, "1")
_ArrayDisplay($a2, "2")
_ArrayDisplay($a3, "3")
_ArrayDisplay($a4, "4")

;$nVisible = -1 "All (Visble or not)", $nVisible = 0 "Not Visible Only", $nVisible = 1 "Visible Only"
Func _WinGetHandleByPID($vProc, $nVisible = 1)
    $vProc = ProcessExists($vProc);
    If Not $vProc Then Return SetError(1, 0, 0)
    Local $aWL = WinList()
    Local $aTemp[UBound($aWL)][2], $nAdd = 0
    For $iCC = 1 To $aWL[0][0]
        If $nVisible = -1 And WinGetProcess($aWL[$iCC][1]) = $vProc Then
            $nAdd += 1
            $aTemp[$nAdd][0] = $aWL[$iCC][0]
            $aTemp[$nAdd][1] = $aWL[$iCC][1]
        ElseIf $nVisible = 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _
                BitAND(WinGetState($aWL[$iCC][1]), 2) = 0 Then
            $nAdd += 1
            $aTemp[$nAdd][0] = $aWL[$iCC][0]
            $aTemp[$nAdd][1] = $aWL[$iCC][1]
        ElseIf $nVisible > 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _
                BitAND(WinGetState($aWL[$iCC][1]), 2) Then
            $nAdd += 1
            $aTemp[$nAdd][0] = $aWL[$iCC][0]
            $aTemp[$nAdd][1] = $aWL[$iCC][1]
        EndIf
    Next
    If $nAdd = 0 Then Return SetError(2, 0, 0);No windows found
    ReDim $aTemp[$nAdd + 1][2]
    $aTemp[0][0] = $nAdd
    Return $aTemp
EndFunc

Looks like setting the parameter to 1 should get you what you want. :)

M23

Edited by Melba23
Found example

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Mordred

Just wanted to say that this solution worked great for me with foobar2000 (because the Window title is completely different depending on what's playing). Here's my script for the lazy:

Edit: Turns out this didn't work in all situations. I modified the script above so that it only finds the foobar2000.exe process window if it is visible or if it is minimized. This means it's not attempting to close any of the multiple hidden windows that foobar scripts could have.

#include <array.au3>
Local $a1

$PID = ProcessExists("foobar2000.exe") ; Will return the PID or 0 if the process isn't found.
If $PID Then
   $a1 = _WinGetHandleByPID($PID, 3)
   ;_ArrayDisplay($a1)
   For $i = 1 To $a1[0][1]+1
      WinClose($a1[$i][1])
   Next
EndIf
Exit

;$nVisible = -1 "All (Visble or not)", $nVisible = 0 "Not Visible Only", $nVisible = 1 "Visible Only", 2 = "Minimized", 3 = "Visible or Minimized"
Func _WinGetHandleByPID($vProc, $nVisible = 1)
   $vProc = ProcessExists($vProc);
   If Not $vProc Then Return SetError(1, 0, 0)
   Local $aWL = WinList()
   Local $aTemp[UBound($aWL)][2], $nAdd = 0
   For $iCC = 1 To $aWL[0][0]
   If $nVisible = -1 And WinGetProcess($aWL[$iCC][1]) = $vProc Then
 $nAdd += 1
 $aTemp[$nAdd][0] = $aWL[$iCC][0]
 $aTemp[$nAdd][1] = $aWL[$iCC][1]
   ElseIf $nVisible = 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And BitAND(WinGetState($aWL[$iCC][1]), 2) = 0 Then
 $nAdd += 1
 $aTemp[$nAdd][0] = $aWL[$iCC][0]
 $aTemp[$nAdd][1] = $aWL[$iCC][1]
   ElseIf $nVisible = 1 And WinGetProcess($aWL[$iCC][1]) = $vProc And _
BitAND(WinGetState($aWL[$iCC][1]), 2) Then
 $nAdd += 1
 $aTemp[$nAdd][0] = $aWL[$iCC][0]
 $aTemp[$nAdd][1] = $aWL[$iCC][1]
   ElseIf $nVisible = 2 And WinGetProcess($aWL[$iCC][1]) = $vProc And BitAND(WinGetState($aWL[$iCC][1]),16) Then
 $nAdd += 1
 $aTemp[$nAdd][0] = $aWL[$iCC][0]
 $aTemp[$nAdd][1] = $aWL[$iCC][1]
   ElseIf $nVisible = 3 And WinGetProcess($aWL[$iCC][1]) = $vProc And (BitAND(WinGetState($aWL[$iCC][1]),16) Or BitAND(WinGetState($aWL[$iCC][1]), 2)) Then
 $nAdd += 1
 $aTemp[$nAdd][0] = $aWL[$iCC][0]
 $aTemp[$nAdd][1] = $aWL[$iCC][1]
   EndIf
   Next
   If $nAdd = 0 Then Return SetError(2, 0, 0);No windows found
   ReDim $aTemp[$nAdd + 1][2]
   $aTemp[0][0] = $nAdd
   Return $aTemp
EndFunc
Edited by Mordred

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  

×