Sign in to follow this  
Followers 0
aboutblank

*nicely* Close A Program?

13 posts in this topic

#1 ·  Posted (edited)

I'm writing a script to set my computer up for gaming (turn off antivirus services, open xfire, steam, fraps, etc) and I'm also writing a script to reverse it. My question is: How can I *nicely* close a program such as Steam, fraps, or xfire? I don't want ProcessKill or ProcessClose because these don't seem to let the programs shutdown properly. For instance, if I ProcessKill or ProcessClose Trillian.exe, the taskbar icon is still there, and doesn't shutdown properly. WinClose and WinKill don't really shut down programs (as far as I can tell) and have no effect on Trillian at all. I would use menu navigation but these apps don't appear to use standard MS menus and are therefore not automatable. Basically I want to send them the wm_close signal (errrr something close to that) so that they close NICELY and have a chance to finish up what they're doing.

Any suggestions would be WONDERFUL!

Note: A lot of programs clear memory buffers and release memory back to the system when they close, and it would be inefficient to ProcessClose/Kill programs.

Edit: Using XP Pro SP2 :think:

Edited by aboutblank

Share this post


Link to post
Share on other sites



Hi,

hmmh you could use the manul way by automating it. E.g.: WinActivate(theProgramToClose)

and then work with ALT+F4 or whatever keystroke-combination you need to terminate the program manually.

After it, you have to react on the possible windows like Save YES/NO and so on.

Without WinActivate... also ControlSend() could be possible.

That would be a little static and maybe some little if then else, but it should work.

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

Hi,

hmmh you could use the manul way by automating it. E.g.: WinActivate(theProgramToClose)

and then work with ALT+F4 or whatever keystroke-combination you need to terminate the program manually.

After it, you have to react on the possible windows like Save YES/NO and so on.

Without WinActivate... also ControlSend() could be possible.

That would be a little static and maybe some little if then else, but it should work.

So long,

Mega

Thanks for your reply Mega, but both of those methods assume that the applications makes a window. Fraps, xfire, trillian, etc are mainly tray applications and do not create a window.

Share this post


Link to post
Share on other sites

Specific solution for Trillian 3.1

Trillian lets you set a hotkey such as Ctrl+Alt+Shift+F10 (pick something you don't normally use in other programs) for exiting the program.

Trillian > Trillian Preferences > Advanced Preferences > Automation > click Add button

Event Type == Hotkey, Action Type == Program Action, Action == Trillian: Exit Program

Make sure the ctrl alt shift boxes are checked if you used them in the hotkey

; AutoIt script to close Trillian

Send("^!+{F10}")


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

....

Bump.

Please?

Close tray apps nicely?

Share this post


Link to post
Share on other sites

So is this some arbitrary list of applications or do you know exactly which ones you'll have to deal with? You may need to devise a unique strategy for each if the brute force methos is undesirable.

You may also want to check out SysTray_UDF, Remove ANY systray icon etc.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Thanks for your reply Mega, but both of those methods assume that the applications makes a window. Fraps, xfire, trillian, etc are mainly tray applications and do not create a window.

Are you sure that they don't create windows? Or are they just hidden windows?

Run this within SciTE and see if you recognize the window title:

$var = WinList()

For $i = 1 to $var[0][0]
  If $var[$i][0] <> "" Then ConsoleWrite("Title=" & $var[$i][0] & @LF)
Next
WinClose might just worked - I tested it on two tray apps... ymmv

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

One other way (i dont know if you consider it "nicely")

but you could

Run ("taskmgr.exe")
Send ("t");**repeat # of times as there other programs that start with "t"**
Send ("!E")

I think something like that would close them all the way,

But i don't know.

Probably better off with other peoples reseponses :think:

Share this post


Link to post
Share on other sites

If their tray icons have any colors that are unique to them from the rest of your tray icons, you could always do a pixelsearch for that color and then using the mouse coordinates you get back have your mouse go down and do the necessary clickage.

Share this post


Link to post
Share on other sites

Mabye you want to create a separate user profile. Logoff of the one account and logon to the tweaked profile. You could use StartupCPL to ensure that any programs that autostartup only appear in your normal profile instead of for all users.


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

if nothing else, just use TaskKill. If you don't tell it to force the shutdown, it will allow the app to close gracefully.

Share this post


Link to post
Share on other sites

if nothing else, just use TaskKill. If you don't tell it to force the shutdown, it will allow the app to close gracefully.

HI,

maybe you could play around and improve 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)
;Input
$programm_I = GUICtrlCreateInput("Type here", 16, 184, 201, 21, -1, $WS_EX_CLIENTEDGE)
;Label
$status_L = GUICtrlCreateLabel("Ready...", 16, 216, 203, 17, $SS_SUNKEN)
$headline_L = GUICtrlCreateLabel("Exit Program", 16, 8, 211, 25)
$program_L = GUICtrlCreateLabel("Enter Program", 16, 160, 203, 17, $SS_SUNKEN)
;Button
$Go_B = GUICtrlCreateButton("GO", 126, 64, 89, 30)

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

GUICtrlSetState($taskkill_R, $GUI_CHECKED)
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 Else
        ;;;;;;;
    EndSelect
WEnd

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

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

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

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

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

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

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