如何从 Powershell 设置 Windows 服务权限?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3145044/
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
How to set Windows Services permissions from Powershell?
提问by Ariel
I need to grant a specific account SERVICE_START permissionsfor a given Windows service.
我需要为给定的 Windows 服务授予特定帐户SERVICE_START 权限。
There seems to be some methods for doing so here, but would prefer a method that's native to PowerShell and doesn't require external tools, for ex. by using Get/Set-ACL cmdlets, or calling some .NET API.
似乎有这样做的一些方法在这里,但我们更希望这是原产于PowerShell和不需要外部工具,为前一种方法。通过使用 Get/Set-ACL cmdlet,或调用一些 .NET API。
Does someone know how to do it in that fashion? Thanks in advance.
有人知道如何以这种方式做到这一点吗?提前致谢。
回答by Keith Hill
I think for this you should look into using subinacl.exe
which you can download here. From the download it site it is described as:
我认为为此您应该考虑使用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.
SubInACL 是一个命令行工具,使管理员能够获取有关文件、注册表项和服务的安全信息,并将这些信息从用户传输到用户、从本地或全局组传输到组以及从域传输到域。
Using it from PowerShell appears to be pretty easy:
从 PowerShell 中使用它似乎非常简单:
SUBINACL /verbose=1 /service Spooler /grant=PC\Joe=LQSTOP
Check out this article on using subinaclthat Mark Minasi wrote..
查看这篇关于使用Mark Minasi 写的subinacl 的文章。
回答by Sam
Cold question deserves a partial answer.
冷问题值得部分回答。
Check out http://get-carbon.org/
If you don't want to install carbon on a production server then look a the source (Apache 2.0 Licence) and see if you can utilise the .NET code for your own devices. If I had time I would expand this answer to include example code but for now see these two parts of the repository.
如果您不想在生产服务器上安装 carbon,请查看源代码(Apache 2.0 许可证),看看您是否可以将 .NET 代码用于您自己的设备。如果我有时间,我会扩展此答案以包含示例代码,但现在请参阅存储库的这两部分。
Powershell CmdLet https://bitbucket.org/splatteredbits/carbon/src/29f5983094d048030d6143923f4a6925d1a1a195/Carbon/Service/Grant-ServicePermission.ps1?at=default
Powershell CmdLet https://bitbucket.org/splatteredbits/carbon/src/29f5983094d048030d6143923f4a6925d1a1a195/Carbon/Service/Grant-ServicePermission.ps1?at=default
Uses a .Net object (using system) https://bitbucket.org/splatteredbits/carbon/src/29f5983094d048030d6143923f4a6925d1a1a195/Source/Security/ServiceAccessRights.cs?at=default
使用 .Net 对象(使用系统) https://bitbucket.org/splatteredbits/carbon/src/29f5983094d048030d6143923f4a6925d1a1a195/Source/Security/ServiceAccessRights.cs?at=default
From that it should be a hop skip and a jump to write your own Powershell v3+ native call.
从它应该是一个跳跃和一个跳跃来编写你自己的 Powershell v3+ 本机调用。