Jump to content
Sign in to follow this  
b0x4it

Send exit command to other applications

Recommended Posts

b0x4it

Is there any way to send exit command to other applications in a way that we do it manually. One way is to simply use this code in a batch file

taskkill /t /f /im "ApplicationEXEName.exe"

but if the application does something during the termination, this method doesn't allow it to do the terminate event.

I am looking for a way to do it just like we do it manually e.g. pushing X or File->Exit to make sure that the application successfully terminates the instance.

Thanks

Edited by b0x4it

Share this post


Link to post
Share on other sites
somdcomputerguy

Look at WinClose, WinKill, and ProcessClose in the Helpfile.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
b0x4it

Thank you for your reply. These solutions work fine for most of the cases, but in some cases like Babylon where the it is usually minimized at systray and of course has no File menu:

1. how can I force it to restore and then try to send some key to it?

2. the only way to Exit these kind of applications is to right-click at their icons at systray and then select Exit. Is there any way to do it?

Thanks

Share this post


Link to post
Share on other sites
b0x4it

I have chosen three application that when I close them they do not exit and just minimize to systray. I tried different commands on them to find out what would be the best way to ask an application (even those that are minimized in systray) to Exit in the way we usually do it manually by choosing File->Exit that let the application to save the job.

The chosen applications are:

Babylon

PopPeeper

SyncBack

What I did and experienced:

1. Command ProcessClose used like this: ProcessClose("exename.exe")

a. Babylon: it works even for both up and minimized states

b. PopPeeper: it works even for both up and minimized states

c. SyncBack: it works even for both up and minimized states

2. Command WinClose used like this: WinClose("[CLASS:class name using Au3Info.exe]", "")

a. Babylon: it does not close this app to systray!!!

b. PopPeeper: it works

c. SyncBack: it works

then I realized that the best way may be to just make the application active and send a hotkey like Alt+x to it. then I tried WinActivate

3. Command WinActivate used like this: WinActivate("[CLASS:class name using Au3Info.exe]", "")

a. Babylon: it does not works for both minimized and up-but-in-background states!!!

b. PopPeeper: it works for both minimized and up-but-in-background states.

c. SyncBack: it works just when this app is not minimized and is in background. so it just brings it in foreground. if it is minimized, this command does nothing!!!

at the end I couldn't find any solution to be able to Exit and not Kill different application. Even activating them in order to be able to send some hotkey to them is not working for all of them.

I appreciate if somebody can help me out!

Share this post


Link to post
Share on other sites
somdcomputerguy

Try Sending (after activation of course) or ControlSending Alt-F4 - (like this .. !{F4}) See the Helpfile if necessary for actual syntax.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
b0x4it

thanks for your reply, but it obviously does not work because I can't even activate Babylon. How am I supposed to activate a windows if WinActivate doesn't work on it?

Share this post


Link to post
Share on other sites
somdcomputerguy

Well obviously nothing worked in my previous post either, until you tried and saw what actually did and did not work. Does this Babylon program not even have a window title or something to use with ControlSend? What is the key sequence you would use to exit this program, if it was active and in the foreground? ControlSend that key sequence, maybe that'll work.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
b0x4it

Because I was not successful to even activate Babylon, then I didn't try sending anything to it. Its windows is un-standard (not like common rectangular windows), so its title can not be used. This is all the information that Au3Info shows about it:

>>>> Window <<<<
Title:  Babylon
Class:  #32770
Position:   1215, 428
Size:   576, 418
Style:  0x960A0044
ExStyle:    0x00010000
Handle: 0x007A07E2

>>>> Control <<<<
Class:  
Instance:   
ClassnameNN:    
Name:   
Advanced (Class):   
ID: 
Text:   
Position:   
Size:   
ControlClick Coords:    
Style:  
ExStyle:    
Handle: 

>>>> Mouse <<<<
Position:   1405, 441
Cursor ID:  0
Color:  0x5D8EC0

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
SplitArea


>>>> Hidden Text <<<<

Share this post


Link to post
Share on other sites
somdcomputerguy

ControlSend might work. That program does have a title, and if a control-id is not explicitly passed to ControlSend, it should pass it's 'payload' to the main window of a program.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
b0x4it

I tried

WinClose("Babylon", "")

and interestingly it worked! WinClose does not work in this way:

WinClose("[CLASS:#32770]", "")

and I do not know why??

The I tried ControlSend like this:

ControlSend("Babylon", "", 300, "!{F4}")                    ; 300 is the ControlID of a textbox

and

ControlSend("Babylon", "", "ATL:006EEBC81", "!{F4}")   ;

OR

ControlSend("Babylon", "", "[CLASSNN:ATL:006EEBC81]", "!{F4}")

where ATL:006EEBC81 is the ClassnameNN, but none of them works. Do you have any suggestion?

I also found that if using totalcommander run a au3 file including this:

ControlSend("Babylon", "", "", "!{F4}")

then it will close totalcommander instead of Babylon. So it means that I have to first activate Babylon in order to send some key to it even with ControlSend. Then there would be no different between ControlSend and Send. I tried it on Notepad and experienced same. What do you think?

Edited by b0x4it

Share this post


Link to post
Share on other sites
dexto

I also found that if using totalcommander run a au3 file including this:

ControlSend("Babylon", "", "", "!{F4}")

then it will close totalcommander instead of Babylon. So it means that I have to first activate Babylon in order to send some key to it even with ControlSend. Then there would be no different between ControlSend and Send. I tried it on Notepad and experienced same. What do you think?

Look at the helpfile for WinTitleMatchMode:

Alters the method that is used to match window titles during search  operations.
1 = Match the title from the start (default)

So if the window title start with "Babylon" it would be a valid match.

Share this post


Link to post
Share on other sites
wolf9228

Sorry ... This Reply to another topic

HotKeySet("{F1}", "_SendText")
HotKeySet("{F2}", "_SendKey")
HotKeySet("{ESC}", "Terminate")

While 1
Sleep(150)
WEnd

Func _SendText()
Run("notepad")
WinWait("[CLASS:Notepad]")
Send("!st.+9pI`VR@2",1)
EndFunc

Func _SendKey()
Run("notepad")
WinWait("[CLASS:Notepad]")
Send("{ALTDOWN}",0)
Send("f",1)
Send("{ALTUP}",0)
Send("{CTRLDOWN}",0)
Send("o",1)
Send("{CTRLUP}",0)
EndFunc

Func Terminate()
    Exit 0
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites
somdcomputerguy

ControlSend("Babylon", "", 300, "!{F4}")                    ; 300 is the ControlID of a textbox

Try this: put quotes around 300. So like this ControlSend("Babylon", "", "300", "!{F4}"), also try this, ControlSend("Babylon", "", "", "!{F4}").

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

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  

×