Sign in to follow this  
Followers 0
jevbrowser

close app gracefully

40 posts in this topic

I have searched the forums but can't find the right way to gracefully shutdown my application.  I have tried the following, but it doesn't shut the app down GRACEFULLLY:

ProcessClose("fling.exe")
$PID = ProcessExists("fling.exe") ; Will return the PID or 0 if the process isn't found.
If $PID Then ProcessClose($PID)
Sleep(6000)
$fling = "C:\Program Files (x86)\NCH Software\Fling\fling.exe"
Run ( $fling & "-scanall" )

Fling is an ftp software that does have a window, but it runs in the background, minimized in the tray.  What I need to do is to shut it down GRACEFULLY, then relaunch it so that it will scan my folders and upload my ftp file daily.  Sounds simple, but the above script causes an error message from fling when i RUN it because fling knows that it was NOT shutdown gracefully.  The error message is a window that pops up asking for a response.  Obviously, I can't answer that response and still have the script run automatically and unattended.

So, my question is:  How can I change my code above to GRACEFULLY shutdown fling so that when i relaunch it, it doesn't think it had previously crashed.

Any help is greatly appreciated.

jev

 

Share this post


Link to post
Share on other sites



jevbrowser,

How do you normally shutdown this app? If you can replicate that then the problem will go away. ;)

M23


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

Killing an application by killing it's process always result in exit the application ungracefully.

The only way I can think to exit a application gracefully is by calling the application by some parameter if the application provide it or through it's GUI

Share this post


Link to post
Share on other sites

well, it runs in Win7 StartUp and i NEVER shut it down.  It always runs.  I CAN open the window and use the menu to EXIT the program.

Share this post


Link to post
Share on other sites

ok, so how would i close it gracefully thru it's GUI window?

Share this post


Link to post
Share on other sites

Take a look at the ControlSend function

Share this post


Link to post
Share on other sites

not sure how to use that.  Can you help me out please?

Share this post


Link to post
Share on other sites

right.  i can use the EXIT function in the File Menu.  My problem is that i can't get the pp (GUI) to maximize out of the System Tray.

Share this post


Link to post
Share on other sites

right.  i can use the EXIT function in the File Menu.  My problem is that i can't get the pp (GUI) to maximize out of the System Tray.

 

This is one of many ways:

$pid = ProcessExists("myprocess.exe")

$win = _WinGetByPID($pid, 0)

WinActivate($win[1])

; by smoke_n
Func _WinGetByPID($iPID, $nArray = 1);0 will return 1 base array; leaving it 1 will return the first visible window it finds
    If IsString($iPID) Then $iPID = ProcessExists($iPID)
    Local $aWList = WinList(), $sHold
    For $iCC = 1 To $aWList[0][0]
        If WinGetProcess($aWList[$iCC][1]) = $iPID And _
            BitAND(WinGetState($aWList[$iCC][1]), 2) Then
            If $nArray Then Return $aWList[$iCC][0]
            $sHold &= $aWList[$iCC][0] & Chr(1)
        EndIf
    Next
    If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(1, 0, 0)
EndFunc

 

That will bring the GUI window show up, then you can send some keys to exit the application.

Please add error handler

Share this post


Link to post
Share on other sites

jevbrowser,

Does the systray icon for this app bring up a menu when you right-click? If so does that menu allow you to exit? If it does then automating that would be a better solution than opening the main GUI. ;)

M23


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

jevbrowser,

Does the systray icon for this app bring up a menu when you right-click? If so does that menu allow you to exit? If it does then automating that would be a better solution than opening the main GUI. ;)

M23

 

Great idea! :)

Share this post


Link to post
Share on other sites

Universal,

I put my fling.exe process in Line 1 but I get an error on:

WinActivate($win[1])

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Melba,

.............also, yes, i do indeed get a menu to EXIT on my right-click.  How would i change the code in that case?

Edited by jevbrowser

Share this post


Link to post
Share on other sites

jevbrowser,

This code should open up the tray menu:

#Include <GuiToolBar.au3>

Global $hSysTray_Handle, $iSystray_ButtonNumber

Global $sToolTipTitle = "" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here <<<<<<<<<<<<<<<<<<<<<<<<<<<

$iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle)

If $iSystray_ButtonNumber = 0 Then
    MsgBox(16, "Error", "Icon not found in system tray")
    Exit
Else
    Sleep(500)
    _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right")
EndIf

Exit

;............

Func Get_Systray_Index($sToolTipTitle)

    ; Find systray handle
    $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')
    If @error Then
        MsgBox(16, "Error", "System tray not found")
        Exit
    EndIf

    ; Get systray item count
    Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
    If $iSystray_ButCount = 0 Then
        MsgBox(16, "Error", "No items found in system tray")
        Exit
    EndIf

    ; Look for wanted tooltip
    For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1
        If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) <> 0 Then ExitLoop
    Next

    If $iSystray_ButtonNumber = $iSystray_ButCount Then
        Return 0 ; Not found
    Else
        Return $iSystray_ButtonNumber ; Found
    EndIf

EndFunc
Now there are 2 possibilites:

 

- 1. The menu responds to specific keys (often "x" to exit) - so try a straight Send("x") or other possible keys and see if that works.

- 2. Use Send("{UP}") & Send{"{ENTER}") as required to select and press the correct menu item - I usually find it helpful to add a Sleep(250) in between each Send call to allow the system to respond.

Let me know how you get on. :)

M23


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

Melba,

Error says:   "Icon not found in System Tray"

As you can tell, i am a beginner and not sure how to use the ToolTipTitle.  Is that where i am going wrong with your code?

Sorry.

Jev.

Share this post


Link to post
Share on other sites

 

Universal,

I put my fling.exe process in Line 1 but I get an error on:

WinActivate($win[1])

 

I'm michaelslamet, not universal :P

Try to put _ArrayDisplay($win) before WinActivate($win[1])

What do you get?

PS: put #include <array.au3> on the top of the script

Share this post


Link to post
Share on other sites

jevbrowser,

 

As you can tell, i am a beginner

We all were at one point, so no worries there. :)

When you place the mouse cursor over the icon do you get a small tooltip appearing? It usually gives the name of the app to which the icon belongs. That is the text you need to assign to the $sToolTipTitle variable as that text is what the code uses to look for the correct icon. ;)

M23


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

Michael,

Here is what i have that still pukes on the WinActivate line:

#include <array.au3>
$pid = ProcessExists("fling.exe")


$win = _WinGetByPID($pid, 0)


_ArrayDisplay($win)
WinActivate($win[1])


; by smoke_n
Func _WinGetByPID($iPID, $nArray = 1);0 will return 1 base array; leaving it 1 will return the first visible window it finds
    If IsString($iPID) Then $iPID = ProcessExists($iPID)
    Local $aWList = WinList(), $sHold
    For $iCC = 1 To $aWList[0][0]
        If WinGetProcess($aWList[$iCC][1]) = $iPID And _
            BitAND(WinGetState($aWList[$iCC][1]), 2) Then
            If $nArray Then Return $aWList[$iCC][0]
            $sHold &= $aWList[$iCC][0] & Chr(1)
        EndIf
    Next
    If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(1, 0, 0)
EndFunc

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