使用Set-Service配置服务

时间:2014-01-08 12:30:00

标签: powershell command-line-interface powershell-v3.0

我可以将服务设置为通过Powershell在自己的容器中运行吗?即

Powershell等效于sc config <service name> type= own

的内容是什么

1 个答案:

答案 0 :(得分:2)

您可以在相应的WMI对象上更改服务类型属性。

# get service
$s = (Get-WmiObject win32_service -filter "Name='Fax'")

# change service type
$s.Change($null, $null, 16) # 16 = "Own Process"

您可以在此处找到其他值(http://msdn.microsoft.com/en-us/library/aa384901(v=vs.85).aspx

确保来自change方法的ReturnValue等于0.您可以在上面的链接中找到错误代码的含义。