Click here to Skip to main content
15,881,281 members

Comments by bjorn_ht (Top 9 by date)

bjorn_ht 27-Feb-12 5:29am View    
My knee jerk reaction here was exactly the same - I even think I made a comment alluding to that.

Still lots of software do exactly what the OP wants. There are a lot of scenarios where you want your process to start as a regular user process under a desktop user and you want to provide rudimentary protection for your process. Not necessarily protection from the user as such but from malicious software and from user errors.

For instance, kill all the processes that have systray icons on your own desktop and I bet you at least one of them starts up again by itself.
bjorn_ht 24-Feb-12 11:36am View    
I'm not talking about services, just regular processes you spawn with CreateProcess(). I agree that windows services is not the right thing here.
bjorn_ht 24-Feb-12 11:28am View    
Yes, the processes can be killed or die because you have a bug. The point with the watchdog is to make sure it starts again.

You can do that for instance by letting each process own a named mutex, then the other process can wait for that mutex and it knows the process died unexpetedly if the wait returns WAIT_ABANDONED.

So assuming you have N processes watching each other, then each would at startup
1. Try to obtain ownership of mutex "WATCHDOGMUTEX_n",
- If that fails, exit, watchdog n is already running
2. Call WaitForMultipleObjects on "WATCHHDOGMUTEX_~n" (so all except its own)
3. When that call returns, one of the other processes abandoned the mutex, i.e. died.

You are still vulnerable to programs that go after your processes, but so it should be.
bjorn_ht 24-Feb-12 11:19am View    
Yeah, this is the approach antivirus - and virus for that matter - often take. Even with the watchdog on the local system, you have fairly good protection against users in the task manager since it takes a while to kill a process there, so the remaining process(es) has ample time to restart the process that was killed before the user gets around to killing the next process.
bjorn_ht 24-Feb-12 10:16am View    
No "world class application" even attempts to prevent users from terminating the process.