473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Starting and Ending Processes from a program

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

Nov 20 '05 #1
10 2605
Nak
> 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
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #2
dan
Thank you very much Nick. I'll give it a try.
Best regards,
Dan
"Nak" <a@a.com> wrote in message
news:er**************@TK2MSFTNGP10.phx.gbl...
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
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

Nov 20 '05 #3
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
Nov 20 '05 #4
Nak
> 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
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #5
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" <fi******@tesco.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #6
Hi Jay,

One more step away from the API. :-)
Thanks.

Regards,
Fergus
Nov 20 '05 #7
N M
On Sat, 6 Sep 2003 17:53:23 +0100, "Fergus Cooney"
<fi******@tesco.net> wrote:

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
Nov 20 '05 #8
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
Nov 20 '05 #9
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
Nov 20 '05 #10
N M
Hi Fergus,

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

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

Neill.

On Mon, 8 Sep 2003 09:02:07 +0100, "Fergus Cooney"
<fi******@tesco.net> wrote:
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
Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Jim Hubbard | last post by:
I am reposting a portion of a thread that I am involved in under a new topic because it seems that there are still people that believe the whole "DLL Hell" myth. I hope I can shed some light on...
1
by: michael.esposito | last post by:
I am trying to end excel and word processes that are spawned by program that does mail merge. The processes run under the impersonation of my network login. I have tried GC.Collect() and it doesnt...
27
by: cj | last post by:
I run this program and to exit click the X in the upper right corner. But apparently it isn't really ending the program. If I return to VB and make changes then try to rebuild the app it says the...
5
by: Andy Baker | last post by:
Our VB.NET 2003 application requires several processes to run overnight. I have written a program to perform these processes with a simple user interface to allow the user to switch various options...
2
by: Soren S. Jorgensen | last post by:
Hi, How do I see, from within my main method, in what context my assembly, containing my service program, is executed ?? I want to be able to detect if the assembly is executed by the service...
4
by: JamesB | last post by:
Hi, I need to trap a particular process starting or ending. I have done this using process.start from within my own app, but powers that be really want it to be seperate (i.e. my app should...
34
by: Umesh | last post by:
I want to extract a string abc*xyz from a text file. * indicates arbitrary no. of characters. I'm only able to do it when the string has definite no. of characters or the string length is...
4
by: greg | last post by:
Hi everyone, I have been having some problems with the following: Using System.Diagnostics, I am starting several exe files from withing Program.exe. Is there a way I can pause the execution...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.