Sign in to follow this  
Followers 0
dexto

Ask process to close

17 posts in this topic

Is there a way to send a shutting down command to a process (no window) or some way to politely ask it to exit before using ProcessClose?

Share this post


Link to post
Share on other sites



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]

Share this post


Link to post
Share on other sites

Can that possibly work for the process with no window?

Share this post


Link to post
Share on other sites

It depends on the design of the program. GUI-less programs that support graceful interruption will have some kind of interface for doing this.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

@bo8ster

PID would not be a problem... what could i try for shutdown command?

Share this post


Link to post
Share on other sites

Well SIGTERM is fully compatible with Unix systems, with Windows i found some references using POSIX but i didn't find any code or dll call.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

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]

Share this post


Link to post
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)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

As Jos said, the hidden window is there, and it works. Hidden windows receive every message regular windows receive.

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