Ok so part two of I have no will power experiment is:
Summary Question - Is there a way to set the CanStop property on a windows service dynamically?
Whole Spiel - I have a service that is currently checking and killing processes (IE Games) I have told it to if it's day I'm not allowed. Great. I set the CanStop to false so that I can't just kill the service if I give into the addiction. I have a program that will have a password check (Someone else enters the password) that will stop the service if the password is correct. (If I have serious withdrawals) Problem is using the ServiceController class.
Far as I can tell, ServiceController just is a decorator (yah design patern guess) and so I have no way to get at the actual service it represents. First attempt was Property Info, but I was too dumb to realize what that would be pointless. Second was Field Info because I thought there might be a private field that "represents" the service. As you might guess, both failed.
Any ideas?
EDIT 1 I'd like to avoid having the CanStop value somewhere I can get to it easily like a config file or registry. So I am attempting, though not successfully, to make this completely handled in program.
New (Failed) Attempts:
ManagementObject service; ManagementBaseObject stopService;
service = new ManagementObject("Win32_Service.Name='StopProgram'");
stopService = service .InvokeMethod("StopService", null, null);
Not sure this did anything. I assume it couldn't stop because of the CanStop situation.