Windows Service start and stop without admin privileges

元气小坏坏 提交于 2019-12-22 05:48:47

问题


How to start and stop window service without having admin privileges?

My application launch should start my service same way it has to stop once it is closed. I can do this using "Service Controller "

I can install the service with Admin privilege but for starting and stopping the service should not ask admin privileges.

Can anybody tell me how I can achieve this using c#?


回答1:


I have discovered the way to give a permission to start/stop the service for non admin users. We can provide a group policy for our service so this can be start/stop without administrator privilege. I found two approach to achieve this task.

Approach 1 :

  1. Create the console from “mmc.exe”
  2. Created the blank security template
  3. Created a security database to store the policy information
  4. Change the service permission to the user which we want to give a permission
  5. Applied new security permission ( I referred this blog)

This approach works perfectly fine, I have created two non admin user account in one virtual machine and set the permission from admin account, I could able to start and stop the service from both non admin user accounts. However this approach was not a complete solution for the problem, It involves lot of manual steps. So I start looking automate this process. Result of that I found the approach 2

Approach 2 : Grant the permission using “Subinacl.exe”, SubInACL is a command-line tool that enables administrators to obtain security information about files, registry keys, and services, and transfer this information from user to user, from local or global group to group, and from domain to domain.

I followed the same example of create two non admin user account and execute command SUBINACL /SERVICE \DomainName\MyService /GRANT=DomainName\USERS=TOP so this will grant the user to start/stop the service.



来源:https://stackoverflow.com/questions/10850595/windows-service-start-and-stop-without-admin-privileges

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!