0
我們在遠程機器上有一些winodow服務。我無法使用我的機器上的服務控制器啓動和停止該服務。無法啓動和停止遠程機器的服務
我們在遠程機器上有一些winodow服務。我無法使用我的機器上的服務控制器啓動和停止該服務。無法啓動和停止遠程機器的服務
您可以使用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
感謝您的幫助brheal。但我也想從.net應用程序中完成。 – Denish
要從.net應用程序調用它,請查看[Powershell API](http://msdn.microsoft.com/zh-cn/library/ee895353.aspx)。爲了使它與.net 4一起工作,請參閱[http://stackoverflow.com/questions/2094694/launch-powershell-under-net-4](http://stackoverflow.com/questions/2094694/launch-powershell-下網-4)。 – brheal