问题
Is there a way to start / stop a windows service of a server in a different network
(not \\<server name>
) from an asp.net page?
I tried using ServiceController but it's only work if it's in the same network.
回答1:
RE: ServiceController How to Start/Stop a Windows Service from an ASP.NET app - Security issues
Anything you can do from command line or powershell can be ran from a page (assuming the app pool user has correct permissions etc)
- https://serverfault.com/questions/429426/how-can-i-connect-to-a-windows-server-using-a-command-line-interface-cli
- Run Command Prompt Commands
- How To: Execute command line in C#, get STD OUT results
Powershell is probably your best bet for managing services on a remote server though this will require the server to allow remote powershell.
- Calling Powershell from C# (ASP.NET) - pass custom object?
- http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C
and of course for the topic of powershell resetting/stopping remote services.
- http://www.powershellmagazine.com/2012/08/28/pstip-starting-and-stopping-services-on-remote-computers/
- How to start/stop a service on a remote server using PowerShell - Windows 2008 & prompt for credentials?
Google is definitely your friend on this one :)
来源:https://stackoverflow.com/questions/17097292/start-stop-window-service-from-asp-net-page