How do I grant permissions to remotely start/stop a service using Powershell?
Posted
by
splattered bits
on Server Fault
See other posts from Server Fault
or by splattered bits
Published on 2012-02-06T22:34:41Z
Indexed on
2012/08/29
3:40 UTC
Read the original article
Hit count: 253
powershell
|windows-service
We have a PowerShell script that restarts a service on another computer. When we use PowerShell's built-in service control cmdlets, like so:
$svc = Get-Service -Name MyService -ComputerName myservicehostname
Stop-Service -InputObject $svc
Start-Service -InputObject $svc
We get this error back:
Stop-Service : Cannot open MyService service on computer 'myservicehostname'.
However, when we use sc.exe, like so:
C:\Windows\System32\sc \\myservicehostname stop MyService
C:\Windows\System32\sc \\myservicehostname start MyService
the start and stop succeed.
The user doing the restarting is not an administrator. We use subinacl to grant the user permissions to start/stop and query the service:
subinacl.exe /service MyService /GRANT=MyServiceControlUser=STO
How come PowerShell can't stop my service but sc.exe
can?
© Server Fault or respective owner