【问题标题】:Not able to start and stop service from remote machine无法从远程机器启动和停止服务
【发布时间】:2011-08-04 12:36:06
【问题描述】:

我们在远程机器上有一些 windows 服务。我无法使用我机器上的服务控制器启动和停止该服务。

【问题讨论】:

    标签: service window servicecontroller


    【解决方案1】:

    您可以使用Powershell 并为其提供适当的凭据:

    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*" }
    

    现在你可以使用 $obj 来停止和启动服务了

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

    此外,如果您想查看 $obj 可用的方法和属性,请使用以下命令:

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

    【讨论】: