Click here to Skip to main content
16,007,885 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I'm trying to create a Windows application that will run during startup and, if terminated later on (say, by a user killing it in the task manager), will restart automatically. I was thinking that perhaps creating it as a Windows service would help.

I know that I can add an entry to registry such that my application will be started automatically at bootup, but I need my application to continue running even if it is closed from task manager. Is there a way to detect this somehow, and then to restart it automatically?

Perhaps I could create a Windows service that would act as a "watchdog" - periodically checking for the existence of the process I wish to preserve, and restarting it if it's not running?
Posted
Updated 3-Feb-10 8:36am
v4

wrote:
Adding the app to the registry is another option


What do you think this means ? You can't add an app to the registry.

You need an extra process running, which will start your process if it stops. This process would be a service, even if your app is not.
 
Share this answer
 
Mangeshd wrote:
"i can add exe entry to registry...so sure that my application will be start at bootup..

but i need my application should run forever even if application is closed from task manager...i need the way to detect and handle this...to restart it automatically...

if i start another application to monitor my 1st application and if both application are terminated then?????????????????

how can i start my main applcation.exe???????"



PLEASE edit your post, instead of posting fake answers.

yes, you can use the registry to start your app on startup, but not to restart it.

I told you the only option. There is no way to stop someone from killing both processes. You can make each process search for and start the other, if you want to start war with your users, but you can't make it 100% the case that a user can't kill your processes, you can just make it harder for them. Once your two processes are dead, there is nothing you can do.
 
Share this answer
 
v2
Your service can do that, yes. The issue is, if someone stops the service, then it won't work. And you can't stop that.
 
Share this answer
 
What you are trying to do is make an application which cannot be killed. This is not actually possible so don't try. The reason being that applications live in 'user space' which has a lower level of access rights than 'kernel space' IN HARDWARE. Thus, another program can always tell the kernel to kill your program - that is kind of the whole point of having a kernel (or at least - one of the most important points).

If you really, absolutely, 100% must have this piece of code loaded and running - then you might be able to create a driver for the kernel that then causes the kernel to spawn a user process if that process has 'gone away'. I suspect this:

a) might not work
b) will cause you a whole world of pain
c) cause your program to be universally hated

I suspect the real solution to your problem is to re-engineer the business process which requires you to do such a strange thing as usurp the normal process management of a computer.
 
Share this answer
 
IN .Net u can use Application.Restart(); it will restart application after anyone closes this..but didn't tested if it gets crashed...
 
Share this answer
 
i can add exe entry to registry...so sure that my application will be start at bootup..

but i need my application should run forever even if application is closed from task manager...i need the way to detect and handle this...to restart it automatically...

if i start another application to monitor my 1st application and if both application are terminated then?????????????????

how can i start my main applcation.exe???????
 
Share this answer
 

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