dexto Posted May 28, 2009 Share Posted May 28, 2009 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? Link to comment Share on other sites More sharing options...
bo8ster Posted May 28, 2009 Share Posted May 28, 2009 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 More sharing options...
dexto Posted May 28, 2009 Author Share Posted May 28, 2009 Can that possibly work for the process with no window? Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 28, 2009 Share Posted May 28, 2009 It depends on the design of the program. GUI-less programs that support graceful interruption will have some kind of interface for doing this. Link to comment Share on other sites More sharing options...
bo8ster Posted May 28, 2009 Share Posted May 28, 2009 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 More sharing options...
dexto Posted May 28, 2009 Author Share Posted May 28, 2009 (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 May 28, 2009 by dexto Link to comment Share on other sites More sharing options...
bo8ster Posted May 28, 2009 Share Posted May 28, 2009 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 More sharing options...
dexto Posted May 28, 2009 Author Share Posted May 28, 2009 @bo8ster PID would not be a problem... what could i try for shutdown command? Link to comment Share on other sites More sharing options...
dexto Posted May 28, 2009 Author Share Posted May 28, 2009 (edited) There are different signals you can send to PID and the one that will ask process to terminate is "SIGTERM" ProcessClose uses "SIGKILL" i'm just looking now for the sending method.i found some info on the signals here: http://www.mkssoftware.com/docs/man3/kill.3.asphttp://www.mkssoftware.com/docs/man1/kill.1.asp Edited May 28, 2009 by dexto Link to comment Share on other sites More sharing options...
dexto Posted May 28, 2009 Author Share Posted May 28, 2009 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. Link to comment Share on other sites More sharing options...
dexto Posted May 28, 2009 Author Share Posted May 28, 2009 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.aspxSo 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 More sharing options...
bo8ster Posted May 28, 2009 Share Posted May 28, 2009 (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 May 28, 2009 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 More sharing options...
dexto Posted May 29, 2009 Author Share Posted May 29, 2009 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 More sharing options...
Richard Robertson Posted May 29, 2009 Share Posted May 29, 2009 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 More sharing options...
dexto Posted May 29, 2009 Author Share Posted May 29, 2009 (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 May 29, 2009 by dexto Link to comment Share on other sites More sharing options...
Developers Jos Posted May 29, 2009 Developers Share Posted May 29, 2009 (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 May 29, 2009 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 More sharing options...
Richard Robertson Posted May 30, 2009 Share Posted May 30, 2009 As Jos said, the hidden window is there, and it works. Hidden windows receive every message regular windows receive. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now