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

本文关键字:启动 服务 程检查 检查 | 更新日期: 2023-09-27 18:03:05

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

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

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

ServiceController提供了一个允许指定远程机器名称的构造函数。