Run service with administrator privileges

2019-01-26 18:15发布

问题:

I am developing an application that runs as a windows service. I really need the service to have administrator privileges. I tried with the LocalSystem user, and it does not have enough rights. Is this possible? I tried setting requireAdministrator in the app.config. When I do this, the service starts and then immediately stops. I have tried with other administrator accounts as well, but I get the same results.

回答1:

You just need to run it as an admin user - set the login correctly in the services properties for the service.

Usually though it's best to run as an ordinary user and give it explicit permissions to the resources it needs access to.