Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Service start and stop without admin privileges

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#?

like image 241
Vinay MS Avatar asked Jun 01 '12 12:06

Vinay MS


1 Answers

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.

like image 86
Vinay MS Avatar answered Oct 01 '22 16:10

Vinay MS