-1

How do I force an application to restart even after a user closes it or its process is killed from Task Manager?

I tried using a windows service with a timer but the limitation of windows service is that a user can stop the service.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Sameer
  • 1
  • 1
    Can you clarify your question a bit? It sounds like you want your application re-started if it dies, but I don't see the programming question here. I've edited your title a bit, based on what I _think_ you are trying to ask. – Tim Post Jul 22 '11 at 13:45
  • 1
    As Raymond Chen [likes](http://blogs.msdn.com/b/oldnewthing/archive/2010/07/21/10040699.aspx) [to](http://blogs.msdn.com/b/oldnewthing/archive/2009/12/22/9939868.aspx) [respond](http://blogs.msdn.com/b/oldnewthing/archive/2006/11/01/922449.aspx) to these kinds of questions: I applaud you for having written the most awesome application in the history of the universe. Clearly, it's so compelling that it should override the user's preferences and force itself to always be running. Unfortunately, Windows was not prepared for a program as awesome as this, and there is no supported way to do so. – Daniel Pryden Jul 22 '11 at 15:36
  • I still don't see a programming question here. If you can edit this, please flag your question for moderator attention to be reviewed. For now, I'm closing this as off topic. – Tim Post Jul 22 '11 at 17:50

2 Answers2

4

I tried using a windows service with a timer but the limitation of windows service is that a user can stop the service.

This is not a limitation of Windows Services. It is a limitation of the fact that the user owns the computer and can therefore do basically whatever they want to or with it.

There is no way to create an application that cannot be stopped or quit. Even if you somehow managed to figure out a way to hide your app from Task Manager, a semi-computer-literate user could find another Task Manager-style program that would allow them to quit your application.

Windows (and all other end-user operating systems) are specifically designed and programmed to prevent this type of exceptionally user-hostile behavior, and for very good reason.

This is not a programming problem, and you'll never find a solution through that route. This is something you need to solve through the use of Group Policies in collaboration with your system administrator. Group Policy is the built-in feature that Windows has for limiting the amount of control that individual users have over their computer, including the ability to end tasks and/or stop services.

Ask more questions about this over on Server Fault.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • Some corporate users might argue with you on the fact of "can do basically whatever they want with it". ;) But, yes. Your point stands, and trying to circumvent such measures is usually a sign of bad design in your application to begin with. – J. Steen Jul 22 '11 at 15:09
  • 1
    @J.Steen: Yes. Those corporate users have their machines locked down via Group Policies and other security mechanisms *specifically* designed for this purpose. It isn't accomplished through rogue applications. Those have another name (malware), and are the bane of system administrators everywhere. And however you slice it, it's unlikely to ever work properly trying to do this yourself, so you might as well give up trying to work *against* the system and work *with* it. – Cody Gray - on strike Jul 22 '11 at 15:15
  • Oh, I was agreeing with you, completely. =) – J. Steen Jul 22 '11 at 15:16
0

NOTE:

This is not an answer that you should try implementing. I would have deleted it if not for the interesting comments on this.

Sounds like a virus! :)

You need to have a buddy process or another process that periodically checks for presence of this process. If not found, then restart it.

Mrchief
  • 75,126
  • 20
  • 142
  • 189
  • Won't work -- I can just kill the buddy process, too. It doesn't take very much computer literacy to figure that out. – Cody Gray - on strike Jul 22 '11 at 15:15
  • @Cody, But what if you have -two- buddy processes... or -three-... or... No. I'm obviously kidding. – J. Steen Jul 22 '11 at 15:17
  • 1
    Yeah, doesn't really matter how many buddies you have; I can genocide them all. This is clearly the wrong way to solve this problem because it doesn't hit at the core limitation: the user controls the computer, **not your app**. You need to figure out a way to **change** that hierarchy, not pretend that it doesn't exist. The only correct part of this answer is the first line. Otherwise, making suggestions like this just starts people off down the wrong path, where they'll eventually have wasted a whole lot of time on a program that doesn't do what they want. – Cody Gray - on strike Jul 22 '11 at 15:21
  • @Cody: You _can_ make it work but that's a moot point. As you said, the first line is the correct part of this answer. Sorry if my answer conveyed the wrong sense. – Mrchief Jul 22 '11 at 15:51
  • Post an implementation that "makes it work", and I'll post a detailed explanation of how to get around it. So will a bunch of other people online at places like Super User. The rule is the same: user-mode operating systems like Windows are designed for the **user**. Nothing you do in an attempt to *skirt* the operating system is going to be effective. Yes, I feel like the answer definitely conveys the wrong sense because you *suggest a possible workaround*. Not only is encouraging people towards a workaround a bad idea, but that workaround won't even, well, *work*. – Cody Gray - on strike Jul 22 '11 at 15:53
  • @Cody: There tons of viruses out there which do this effectively, hence the first line to my answer. As much as Windows is designed for the user, a rogue program can also _pretend_ to be an user and pretty much do all the same things. – Mrchief Jul 22 '11 at 15:56
  • Yes, I'm not quibbling with the part about virii. I'm quibbling with the suggestion in the second line. There isn't a button to vote on the bottom-half of an answer only. I agree that a rogue program can pretend to be a user, but the user doesn't have to do any pretending to work around that rogue program. I don't know how else to say it: the second half of this answer seems to be proposing a solution. My argument against that has been two-fold: 1) that won't ever actually work, at least not reliably or in a way that the user can't easily bypass, 2) it encourages *extremely* bad programming. – Cody Gray - on strike Jul 22 '11 at 16:00
  • And I agree with you 100%. I never disagreed but now I have made it explicit (see my note). – Mrchief Jul 22 '11 at 16:01