问题
Is it possible to create a windows service which will be unstoppable until the machine gets shutdown. Because I want to run one of my applications along with the service, is it possible to do it?
Thanks, just tell me how to run my application along with the service.
回答1:
You cannot create a process that is un-killable in Windows. Otherwise Windows would do this to critical processes (kill csrss.exe for a quick BSOD). With careful setting of service and process ACLs you can make it harder, but this can always be beaten with Take Ownership and Debug privileges.
回答2:
So what your asking for is a windows service that cannot be terminated until Windows is closed down, then you want to know if there is a way to attach a program to that service so that it cannot be terminated as well?
I could be wrong, but I doubt if windows would give you the opportinity to create and attach a program to a service which would make it impossible to kill, unless you pulled the plug. i'm guessing you would have to write some sort of extra program to monitor the current one so that it could restart it, if it got closed down.
回答3:
Windows service can be made unstoppable by specifying the dwControlsAccepted of SERVICE_STATUS structure to accept only shutdown.Then use setservicestatus to apply the status. But the process can be killed.Just stopping the service through scm is prevented
回答4:
One way is to set up another service, or a scheduled task, that monitors the services and restarts it.
The value of this approach would really depend on the nature of your tasks. I've seen this approach used to keep a slightly unstable service alive (it was a legacy system and the team didn't have the time to rewrite it immediately, so they used this as a band-aid).
回答5:
As others (particularly Richard) have pointed out, it is virtually impossible to make a Windows process "un-killable".
If your goal is to run your application 24/7, I suggest using a product like AlwaysUp, which will start your application as a service, closely monitor it, and quickly fire it up again if it fails for any reason.
Good luck!
来源:https://stackoverflow.com/questions/712870/windows-services