I am trying to write a windows form app that will let me check/start/stop services on multiple servers. I have my code setup to check services on the local machine but I can't figure out how to check the remote machine:
try
{
ServiceController machsmint = new ServiceController();
machsmint.ServiceName = "MACHSMIntegration";
if (machsmint.Status.ToString().ToLower() == "stopped")
{
label_machsmINTSTATUS.Text = "Service is not Running";
}
if (machsmint.Status.ToString().ToLower() == "running")
{
label_machsmINTSTATUS.Text = "Service is Running";
}
}
catch
{
label_machsmINTSTATUS.Text = "Service is not Running";
}
Where do I need to add the code to connect to the remote machine or am I going in the complete wrong direction here? I'm sorry if this is a stupid question! Thanks!
ServiceController
provides a constructor that allows specifying the name of the remote machine.