Click here to Skip to main content
15,843,593 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, Please excuse my ignorance on the subject since I fairly new to programming. I want to Start, hide as soon as it starts and end a process at some point in the code. Could you please guide me how to do this ? I have tried using the Process class through which I can start it but I am having trouble hiding and ending it.

Thanks for your time !
Posted
Comments
OriginalGriff 19-Feb-15 14:08pm    
Why do you want to hide a process?
Member 11456687 19-Feb-15 15:58pm    
When I say hide, I mean that the window for the exe file doesn't show up to the user. The application I want to start turns on some LED's on my Panel PC and pops up a window which says LED's are on - I don't want the user to see this since he/she is interacting with my other GUI program.
Sergey Alexandrovich Kryukov 19-Feb-15 16:17pm    
What does it mean. "To the user"? What kind of the user? Not showing any windows or not showing the process? The process will be shown in the Task Manager...
If you want just to hide some windows, this is not the universal action. Just read the documentation on the windows API library you use.
—SA

1 solution

Starting process is the usual thing which is always used, otherwise we would not have processes at all. The process is started when you start the application, but it is always done by some other, already executing process (the system startup process bootstraps some of them, so you always have one to start with).

How? Please see:
https://msdn.microsoft.com/en-us/library/System.Diagnostics.Process(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx[^].

Stopping process? It depends what do you mean by stopping. There is only one legitimate way of terminating the process: when execution returns from the entry-point function of some application, main function. This is what really happens on after all those Application.Exit, closing of the main application window, and other numerous ways of quitting the applications, depending on all the technologies, languages and libraries. One special case is perhaps running on the top stack frame of the process's main thread which has the same effect and can also be considered acceptable, especially in some simple console-only applications. Note that it may not work in all cases. If you have any number of non-background threads other then main process thread, each of them will keep the process loaded, continuing the execution. All those threads should also exit their execution before the process can be terminated and unloaded.

Any other way of stopping the process is a bad thing. You really can terminate (kill) any process which is not ready to quit its execution. It can be considered only as a temporary measure if you have no other choice. For example, due to some bugs, you failed to find how to terminate all those non-background threads, or you have some external process which does not behave properly (bugs, extremely poor quality), not accessible for your patching. This is how this bad thing can be done: https://msdn.microsoft.com/en-us/library/system.diagnostics.process.kill%28v=vs.110%29.aspx[^].
This can work for both calling process or some other process, if your calling process has enough privileges to kill another one. Don't do it! Always try to fix those bugs.

If you need to stop one process by another process, the only legitimate way is this: you need to pass some notification to another process to request it to stop itself. Then, eventually, that process should quit execution in some of standard ways of doing so (ultimately, exit entry-point function). Naturally, that process should be designed for such kind of collaboration. In all cases, the notification mechanism is one of the IPC facilities, there are many of them, such as named pipe, messages, sockets.

And finally, shall we even discuss hiding of the process? I would not. I think this is the hack only attempted by some malicious software. I would stop this topic at this point. If you can mention any legitimate purpose of doing such things, I will gladly discuss it. But if you just want to hide some windows, please see my comment to the question above.

—SA
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900