Jump to content

Ask process to close


Recommended Posts

I would go with send. I assume that the program accepts shutdown commands from the keyboard. Crude I know - thats how I do it.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Yes

You either can use send within a dos window or use StdinWrite using the PID.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

@Richard Robertson

If so, how to use Send or ControlSend if i know nothing of the window or control?

@bo8ster

would i send Alt{f4} to StdinWrite of the precess..?

most of the processes are not cmd... (with knows exit commands)

Edited by dexto
Link to comment
Share on other sites

Without knowing much about the process it is hard to know what to send it.

Once you get the PID - ProcessExists will give that to you - you can send the process anything you want. I am assuming that the program does have a shutdown command - if not and it only has start, I think your out of options.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Ok guys,

Here what it is:

I'll assume you have, or know how to obtain, the window handle (hWnd) of the application you want to kill. If not, numerous examples are on my Web site at www.mvps.org/vb and in previous columns I've written. Just as in real life, things work out most smoothly when everyone's in agreement. The easiest way to shut down another app is to ask it nicely. You can do this by sending the other app a WM_CLOSE message.

Sending WM_CLOSE to the window handle you have isn't sufficient typically because most applications comprise numerous windows. The answer: Find all the top-level windows belonging to this application and send the message to each. Start by determining the application's process ID. This is a unique 32-bit value that you can obtain using a call to GetWindowThreadProcessId. Pass the known hWnd as the first parameter, and a variable to accept the process ID as the second.

http://msdn.microsoft.com/en-us/library/aa287954.aspx

So as Richard Robertson mentioned there is no way to gently kill the application if it has no window unless you find out how to trigger exit for that particular program.

The only way out is to use WinClose

Link to comment
Share on other sites

This seems a little strange as you said it is not a window so using windows specific messages will not work. Since it will be running on windows (or AutoIt will not work) I assumed it will be a child process of a windows process.

Good programs catch events like close commands and shut down them correctly - that is why something like WM_CLOSE works.

Richard is correct - you have to know more about the program's interface.

Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

I remember having trouble catching the shutdown signal with onAutoItExit() (i didn't have a window) i guess that just confirms why Windows programs are not as stable as Unix based (where they actually have different signals that can be sent to a process)

Link to comment
Share on other sites

You have no idea what you are talking about. Windows programs can be just as stable as Unix programs. It depends on the design of the program. You also switched back and forth on what you are saying several times.

You don't need your own window to catch shutdown in OnAutoItExit() because AutoIt has its own hidden window.

Link to comment
Share on other sites

Thank you for noting. That only confirms my findings (a new discovery for myself) and what i mentioned above: processes without hidden/visible window can't receive shutdown notifications in Windows.

If you feel like waisting time you can highlight where i was wrong. If i changed my mind is only because i found more information to support or disprove what i learned from available sources. Thank you for being one of them.

As for stability its always about the design and the designer using tools available yet you have to admit that Windows has less choses in signals.

Edited by dexto
Link to comment
Share on other sites

  • Developers

I remember having trouble catching the shutdown signal with onAutoItExit() (i didn't have a window) i guess that just confirms why Windows programs are not as stable as Unix based (where they actually have different signals that can be sent to a process)

I assume Richard was talking about this post as this doesn't make much sense really.

AutoIt3 always has a GUI running in the background and when a shutdown message is received, autoit3 will perform onAutoItexit() before shutting down.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...