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.
Asked
Active
Viewed 169 times
1 Answers
2
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

brheal
- 1,237
- 8
- 14
-
Thanks for help brheal. but i want to do it from .net application too. – Denish Aug 05 '11 at 05:49
-
To call it from a .net app check out the [Powershell API](http://msdn.microsoft.com/en-us/library/ee895353.aspx) . To get it to work with .net 4 see [http://stackoverflow.com/questions/2094694/launch-powershell-under-net-4](http://stackoverflow.com/questions/2094694/launch-powershell-under-net-4). – brheal Aug 05 '11 at 13:56