简体   繁体   English

Windows服务启动和停止没有管理员权限

[英]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:

  1. Create the console from “mmc.exe” 从“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 结果我找到了方法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.

相关问题 是否可以在没有管理员权限的情况下安装,启动和停止Windows服务? - Is possible to install ,start and stop the windows service without admin rights? 是否可以将应用程序配置为在 Windows 启动时启动而无需管理员权限? - Is it possible to configure app to start on Windows startup without requiring Admin privileges? 通过C#启动/停止Windows服务,并以管理员身份运行,而没有UAC提示窗口 - start / stop windows service via C# with run as admin without UAC prompt window 如何以管理员身份启动Windows Service - How to Start Windows Service As Administrator Privileges 如何在 C# 中制作一个独立的可执行文件,该可执行文件将在没有管理员权限且用户无需执行任何操作的情况下安装 windows 服务? - How do I make a standalone executable in C# that will install a windows service without admin privileges and without the user having to do anything? Windows 7中的代码中的停止/启动服务 - Stop/Start service in code in Windows 7 在构建中停止并启动Windows服务 - Stop And Start Windows Service On Build 如何在OS Windows启动时始终以管理员权限启动WPF应用 - how to start always a wpf app with admin privileges when the os windows start Windows服务启动,停止,调试问题 - Windows service start, stop, debug problems Windows启动时停止应用程序服务 - Stop service of Application When Windows Start
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM