Starting and Ending Processes from a program

  • Thread starter Thread starter dan
  • Start date Start date
D

dan

1.
I have created a program P1 which is going to be triggered by a Windows
Service. What command should be added in the Sub OnStop to force the
process P1 to end when the service is stopped?
2.
I am using the method Shell to start a program P2 from a program P3. What
method can be used to end the program P2?
Many thanks,
Dan
 
I have created a program P1 which is going to be triggered by a Windows
Service. What command should be added in the Sub OnStop to force the
process P1 to end when the service is stopped?

I'm think that might depend on whether you want the application to end
gracefully or not. Is it your application that is being run? and is it a
..NET application? If so then you might want to get into remoting to enable
you to send a command to the application the shut down. If not then it is a
completely different ball game, it would require terminating the process,
but what if it is busy doing something important at the time? Take a look
at the following like, it looks like it could help you...

http://www.buygold.net/v06n04/v06n04.html

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Hi Dan,

Another way is good old-fashioned Windows messages.

You can either send a WM_CLOSE, or a user-message of your own making (if P1 and P2 are yours and editable).

Regards,
Fergus
 
You can either send a WM_CLOSE, or a user-message of your own making
(if P1 and P2 are yours and editable).

Good point, I hadn't thought of that one! :-)

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Fergus,
System.Diagnostics.Process.CloseMainWindow will send the WM_CLOSE to the
main window of the process for you.

Actually I'm not sure if it sends WM_CLOSE or a WM_QUIT, either way it
causes the other application to close, assuming the other application is a
Windows Application & not a Console Application.

Hope this helps
Jay

Fergus Cooney said:
Hi Dan,

Another way is good old-fashioned Windows messages.

You can either send a WM_CLOSE, or a user-message of your own making
(if P1 and P2 are yours and editable).
 
On Sat, 6 Sep 2003 17:53:23 +0100, "Fergus Cooney"

Hi Fergus,

This 'user-message of your own making' you mentioned...how would you
send this, and what would you be doing (or trapping) in the other
application to act on this?

Thanks in advance,

Neill.
Hi Dan,

Another way is good old-fashioned Windows messages.

You can either send a WM_CLOSE, or a user-message of your own making (if P1 and P2 are yours and editable).

Regards,
Fergus

______________________________________________
WORK: n e i l l @ f u z z y g o a t . c o m
WEB: www.fuzzygoat.com
 
Hi Niall,

You can send messages to Windows using SendMessage() or PostMessage() of
Win32 Api fame. These takes a Window Handle as the first argument. If the
handle is unavailable, you can use HWND_BROADCAST (0xFFFF) which will send the
message to all Windows in the system.

There is also PostThreadMessage() which takes a Windows Thread Id as the
first parameter.

User-defined messages are simply those with a number of your choosing. The
base for these is WM_APP which is defined as 0x8000 and the range continues to
0xBFFF.

If you send or post a broadcast message (using HWND_BROADCAST) you can't
choose an arbitrary value in case another application is also using it. In
this case you must call RegisterWindowMessage() which will return a unique
message id for you to use.

All controls, including forms, have a WndProc. In .NET this can be
overriden so that you can intercept messages to the control.

Hope this helps with your hidden applications problem. :-)

Regards,
Fergus
 
Hi again Niall,

If you have your other application's Process (System.Diagnostics.Process)
you can access the Threads collection to get the application's threads. These
have an Id property which is the Windows Id.

Regards,
Fergus
 
Hi Fergus,

I see you spotted my main message too. :-)

I'll give it a go and thanks for your help.

Neill.

Hi again Niall,

If you have your other application's Process (System.Diagnostics.Process)
you can access the Threads collection to get the application's threads. These
have an Id property which is the Windows Id.

Regards,
Fergus

______________________________________________
WORK: n e i l l @ f u z z y g o a t . c o m
WEB: www.fuzzygoat.com
 
Back
Top