远程检查/启动/停止服务

时间:2013-03-08 16:48:33

标签: c# service remoting restart

我正在尝试编写一个Windows窗体应用程序,它可以让我检查/启动/停止多个服务器上的服务。我有我的代码设置来检查本地机器上的服务,但我无法弄清楚如何检查远程机器:

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

我需要在哪里添加连接到远程计算机的代码,或者我在这里完全错误的方向?如果这是一个愚蠢的问题,我很抱歉!谢谢!

1 个答案:

答案 0 :(得分:2)

ServiceController提供constructor,允许指定远程计算机的名称。

相关问题