Search code examples
servicewindowservicecontroller

Not able to start and stop service from remote machine


We have some winodow services on the remote machine. I am not able to start and stop that services using service controller from my machine.


Solution

  • You can use Powershell and supply it with the appropriate credentials:

    PS C:\Users\YourUserName>$remoteComp = "remoteComputerName"
    PS C:\Users\YourUserName>$svc = "Service Name"
    PS C:\Users\YourUserName>$c = Get-Credential
    PS C:\Users\YourUserName>$obj = (gwmi -computername $comp -class Win32_Service -computer $remoteComp -Credential $c | Where-Object { $_.Name -match "^$svc*" }
    

    Now you can use $obj to stop and start the service

    PS C:\Users\YourUserName>$obj.StopService()
    PS C:\Users\YourUserName>$obj.StartService()
    

    In addition, if you want to see the methods and properties available for $obj use this command:

    PS C:\Users\YourUserName>$obj | Get-Member