【问题标题】:Remotely Check/Start/Stop Services远程检查/启动/停止服务
【发布时间】:2013-03-08 16:48:33
【问题描述】:

我正在尝试编写一个 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";
        }

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

【问题讨论】:

    标签: c# service remoting restart


    【解决方案1】:

    ServiceController 提供了一个constructor,允许指定远程机器的名称。

    【讨论】:

    • 好的,所以我将我的服务控制器更改为:ServiceController machsmint = new ServiceController("MACHSMIntegration", "SERVER1"); 这现在适用于运行 Windows 2003 但运行 2008(sp2) 的服务器不工作的服务器。 2008 年有什么不同的事情我需要做的吗?
    • 我认为我已将其缩小到安全设置 b/c 我的 2003 服务器使用 NT 凭据,但我的 2008 服务器使用本地用户。有没有办法将它与模仿者类之类的东西一起使用来模仿该本地用户?