windows C#。如何以编程方式授予用户登录作为服务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1286795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:00:13  来源:igfitidea点击:

C#. How to programmatically grant User Log On as a Service

c#windowslocal-security-policy

提问by MaksymD

I've searched through the internet, but haven't found any solution in c#. Does anybody know how to give user right to log on as a Service in c#?

我已经通过互联网进行了搜索,但没有在 c# 中找到任何解决方案。有人知道如何授予用户在 c# 中作为服务登录的权限吗?

采纳答案by GuyBehindtheGuy

EDIT: I found an articleon CodeProject with sample code that shows exactly how to do this!

编辑:我在 CodeProject 上找到了一篇带有示例代码的文章,其中显示了如何做到这一点!

I assume you've already found this KBthat shows how to do it with native code. I'm looking for a C# way as well.

我假设您已经找到了显示如何使用本机代码执行此操作的 KB。我也在寻找一种 C# 方式。

回答by No More Hacks

I tried in vain to find this. The way I did it in the end was to package the NTRights executable with my application and then launch it as a separate process.

我徒劳地试图找到这个。我最终的做法是将 NTRights 可执行文件与我的应用程序打包在一起,然后将其作为单独的进程启动。

NTRights can be found on the server 2003 resource kti and its usage is documented here: http://support.microsoft.com/kb/315276

NTRights 可以在 server 2003 资源 kti 上找到,其用法记录在此处:http: //support.microsoft.com/kb/315276