[英]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. 我可以使用Admin权限安装服务,但是启动和停止服务不应该要求管理员权限。
Can anybody tell me how I can achieve this using c#? 任何人都可以告诉我如何使用c#实现这一目标?
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:
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
结果我找到了方法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. 方法2:使用“Subinacl.exe”授予权限,SubInACL是一个命令行工具,使管理员能够获取有关文件,注册表项和服务的安全信息,并将此信息从用户传输到用户,从本地或全局组传输分组,从域到域。
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. 我按照创建两个非管理员用户帐户的相同示例执行命令SUBINACL / SERVICE \\ DomainName \\ MyService / GRANT = DomainName \\ USERS = TOP,这样就可以授予用户启动/停止服务的权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.