How to prevent an app from being killed in task manager?

10,822

Make it so that the WPF side is just a client. The "server" in this case must be a Windows Service. Then set the Service to start automatically (this last part requires admin privileges). Bonus if it runs as a network admin.

If the service's process is killed, Windows starts it again immediately. And then no matter what users try, they can't really stop your program's logic unless they have admin powers and stop the service themselves. Use the WPF GUI just for configuration.

Share:
10,822
newman
Author by

newman

Updated on July 19, 2022

Comments

  • newman
    newman almost 2 years

    I'm working on a parental control app (written in WPF) and would like to disallow anybody (including administrator) to kill my process. A while back, I found the following code online and it almost works perfectly, except that it doesn't work sometimes.

    static void SetAcl()
    {
        var sd = new RawSecurityDescriptor(ControlFlags.None, new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null), null, null, new RawAcl(2, 0));
        sd.SetFlags(ControlFlags.DiscretionaryAclPresent | ControlFlags.DiscretionaryAclDefaulted);
        var rawSd = new byte[sd.BinaryLength];
    
        sd.GetBinaryForm(rawSd, 0);
        if (!Win32.SetKernelObjectSecurity(Process.GetCurrentProcess().Handle, SecurityInfos.DiscretionaryAcl, rawSd))
            throw new Win32Exception();
    }
    

    In Win7, if the app is started by the logged in user, even the admin cannot kill the process (access denied). However, if you switch to another user account (admin or standard user), then check "Show processes for all users", then you kill the process without a problem. Can anybody give me a hint why and how to fix it?

    EDIT:
    I understand some people are upset by this question, but here is my dilemma. This is a parental control I wrote primarily for my own use. The main feature is that I want to monitor and limit my kids' on games (not simply turn off all games). I could assign kids a standard user account and they cannot kill the process. However, some games (e.g. Mabinogi) require admin right to be playable. So, I had to type in my admin password each time, which is annoying.

    By the way, I'm not sure if it's against Stackoverflow's policy, here is my app if you'd like to check it out: https://sites.google.com/site/goppieinc/pc-screen-watcher.

    EDIT:
    My main point of this post is to ask if somebody could give me a hint why the posted code doesn't always work - e.g. in case you show processes for all users.

  • newman
    newman almost 11 years
    Thank you very much for the tip. I was thinking about this approach too. However, as I mentioned, giving kids a standard account is a problem. I wish Windows has more granular control over the account for admin.
  • Geeky Guy
    Geeky Guy almost 11 years
    Give each kid a Steam account. That way you know what they're playing just by checking their profile (it has a social network side, and you can't hide what you've been playing, for how long etc.). You'll have a lot more control over what they play, since they'll only play what you buy them (note that there is no signature fee).
  • newman
    newman almost 11 years
    I don't know what Steam is, but I know my kids do have it on their computer. The problem I try to solve with my program is that I want to grant my kids certain time of games (e.g. max 2 hrs per day on weekends, and no game during weekdays). I don't care which game they play as long as time allows. The games they play change from time to time. Besides, I can monitor all the activities on their computers as long as my screen watcher is on...
  • Geeky Guy
    Geeky Guy almost 11 years
    Steam will help you with that as well. It acts as a launcher to the games, so killing Steam's process kills whatever they are playing too.
  • newman
    newman almost 11 years
    Well, I just looked it up and I don't see any parental control function in Steam. Actually, many people are asking for that. Besides, I saw kids playing games without running steam.
  • Geeky Guy
    Geeky Guy almost 11 years
    You don't need Steam to play games. You need Steam to play the games you bought (or were given) through Steam. As for the parental function, yeah it doesn't have one. I just mentioned it because you want to kill processes, and the Steam Client process is a parent process of any game's that's started through it.