jevbrowser Posted January 21, 2014 Posted January 21, 2014 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
Moderators Melba23 Posted January 21, 2014 Moderators Posted January 21, 2014 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
michaelslamet Posted January 21, 2014 Posted January 21, 2014 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
jevbrowser Posted January 21, 2014 Author Posted January 21, 2014 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.
jevbrowser Posted January 21, 2014 Author Posted January 21, 2014 ok, so how would i close it gracefully thru it's GUI window?
michaelslamet Posted January 21, 2014 Posted January 21, 2014 Take a look at the ControlSend function
jevbrowser Posted January 21, 2014 Author Posted January 21, 2014 not sure how to use that. Can you help me out please?
l3ill Posted January 21, 2014 Posted January 21, 2014 Most programs have a close or exit in the File Menu, sometime with their own Keyboard Shortcut. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
jevbrowser Posted January 21, 2014 Author Posted January 21, 2014 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.
michaelslamet Posted January 21, 2014 Posted January 21, 2014 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
l3ill Posted January 21, 2014 Posted January 21, 2014 Have a look at the suggestion from michaelslamet. ControlSend does not need an active window to work just the control ID or Handle. Not sue if PID will work youll have to test that. My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
Moderators Melba23 Posted January 21, 2014 Moderators Posted January 21, 2014 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
michaelslamet Posted January 21, 2014 Posted January 21, 2014 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!
jevbrowser Posted January 21, 2014 Author Posted January 21, 2014 Universal, I put my fling.exe process in Line 1 but I get an error on: WinActivate($win[1])
jevbrowser Posted January 21, 2014 Author Posted January 21, 2014 (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 January 21, 2014 by jevbrowser
Moderators Melba23 Posted January 21, 2014 Moderators Posted January 21, 2014 jevbrowser,This code should open up the tray menu:expandcollapse popup#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 EndFuncNow 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
jevbrowser Posted January 21, 2014 Author Posted January 21, 2014 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.
michaelslamet Posted January 21, 2014 Posted January 21, 2014 Universal, I put my fling.exe process in Line 1 but I get an error on: WinActivate($win[1]) I'm michaelslamet, not universal Try to put _ArrayDisplay($win) before WinActivate($win[1]) What do you get? PS: put #include <array.au3> on the top of the script
Moderators Melba23 Posted January 21, 2014 Moderators Posted January 21, 2014 jevbrowser, As you can tell, i am a beginnerWe 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
jevbrowser Posted January 21, 2014 Author Posted January 21, 2014 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
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