Jump to content

Send exit command to other applications


Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 <<<<
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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

 

Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...