如何从Powershell设置Windows服务权限?

时间:2010-06-29 21:53:23

标签: windows security powershell service

我需要为给定的Windows服务授予特定帐户SERVICE_START permissions

似乎有一些方法可以这样做here,但更喜欢PowerShell原生的方法,并且不需要外部工具,例如。通过使用Get / Set-ACL cmdlet或调用某些.NET API。

有人知道如何以这种方式做到这一点吗?提前谢谢。

2 个答案:

答案 0 :(得分:2)

我认为你应该考虑使用subinacl.exedownload here。从下载它的网站,它被描述为:

  

SubInACL是一个命令行工具,使管理员可以获取   有关文件的安全信息,   注册表项和服务,以及   将此信息从用户传输到   用户,从本地或全球组到   组,从域到域。

从PowerShell中使用它看起来非常简单:

SUBINACL /verbose=1 /service Spooler /grant=PC\Joe=LQSTOP

查看Mark Minasi写的article on using subinacl ..

答案 1 :(得分:1)

冷酷的问题值得部分回答。

查看http://get-carbon.org/

如果您不想在生产服务器上安装carbon,那么查看源代码(Apache 2.0许可证),看看您是否可以将.NET代码用于您自己的设备。如果我有时间,我会扩展这个答案以包含示例代码,但现在看到存储库的这两部分。

Powershell CmdLet https://bitbucket.org/splatteredbits/carbon/src/29f5983094d048030d6143923f4a6925d1a1a195/Carbon/Service/Grant-ServicePermission.ps1?at=default

使用.Net对象(使用系统) https://bitbucket.org/splatteredbits/carbon/src/29f5983094d048030d6143923f4a6925d1a1a195/Source/Security/ServiceAccessRights.cs?at=default

从那以后它应该是跳跃跳跃和跳转来编写你自己的Powershell v3 +原生呼叫。