如何在 .net 中为 Windows 服务设置 ACL? [英] How do I set ACL for a Windows Service in .net?

查看:13
本文介绍了如何在 .net 中为 Windows 服务设置 ACL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一项服务,需要通过按钮启动和停止.我在一个单独的程序中使用 ServiceController,当我以管理员身份运行这个单独的程序时,一切都按预期工作.但是,我需要能够像任何人一样控制这项服务.如何为我的服务设置权限,以便每个人都可以完全控制它?这需要作为服务的一部分或安装以编程方式完成.是用vb.net编写的localservice.

I have a service that I need to be able to start and stop with a button. I am using a ServiceController in a seperate program and everything works as intended when I run this seperate program as an administrator. However, I need to be able to control this service as anyone. How can I set the permissions for my service so that everyone has full control of it? This needs to be done programatically as either part of the service, or the install. It is a localservice written in vb.net.

推荐答案

您有几个选择:

1) 您可以要求您的应用程序以管理员身份运行.每次您的应用程序启动时,系统都会提示您使用 UAC(在 Windows 7 和 Vista 上),您的应用程序将被提升到所需的级别.

1) You can require that your application runs as an administrator. Every time your application starts, you will be prompted with the UAC (on Windows 7 and Vista) and your application will be elevated to the required level.

以管理员身份运行 .NET 应用程序

2) 当需要停止和启动服务时,您的应用程序可以请求提升.它将通过在更高级别启动另一个应用程序来实现这一点,而另一个应用程序将执行实际的启动和停止.

2) Your application can request an elevation when the action is required to stop and start the service. It would do this by starting another application at a higher level and this other application will do the actual start and stop.

如何仅在需要时提升权限?

3) 首选选项,恕我直言——您应该构建您的服务以始终运行,但除了通过 TCP/IP、命名管道或其他一些通信机制侦听请求之外,不要做任何其他事情.然后,您的服务可以启动或停止执行实际工作的线程.

3) Preferred option, IMHO - You should build your service to run all of the time but just not do anything other than listen for requests via TCP/IP, Named Pipes or some other communication mechanism. Your service can then start or stop a thread that performs the real work.

4) 您可以修改服务权限.以下是一些提供有关此信息的帖子(我仍然更喜欢选项 3):

4) You can modify the service rights. Here are some posts that give some information on this (I would still prefer option 3):

启动/停止 Windows 服务非管理员用户帐户

http://msmvps.com/blogs/erikr/archive/2007/09/26/set-permissions-on-a-specific-service-windows.aspx

http://fstaal01.home.xs4all.nl/swsc-us.html

更新

我已根据 Harry 的评论更改了一些文本并添加了选项 4.似乎有一些方法可以调整权限.这些最初需要管理员权限,但如果您将 swsc(第三个链接)之类的东西与您的安装捆绑在一起,您可以使用它来为您设置权限.我不确定这样做是否对许可证有任何影响.或者,您可以使用他粘贴的代码的变体.

I have changed some text and added option 4 based on Harry's comment. It seems that there are ways of tweaking the permissions. These require administrator rights initially but if you bundle something like swsc (third link) with your installation, you could use it to set the rights for you. I am not sure if there are any license implications for doing this. Alternatively, you could use a variant of the code he pasted.

这篇关于如何在 .net 中为 Windows 服务设置 ACL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆