• λ我爱Aspx >> Asp.Net >> 使用C#控制远程计算机的服务
  • 使用C#控制远程计算机的服务

  • :未知  Դ:internet  :2007-5-20 16:43:53  ؼ:c#
  • try

    {

    //判断是否可以暂停

    if((bool)mo["acceptPause"]&&(string)mo["State"]=="Running")

    mo.InvokeMethod("PauseService",null);

    }

    catch(ManagementException e)

    {

    strRst =e.Message;

    }

    return strRst;

    }

    // 恢复指定的服务

    public string ResumeService(string serviceName)

    {

    string strRst = null;

    ManagementObject mo = this.managementClass.CreateInstance();

    mo.Path = new ManagementPath(this.strPath+".Name=\""+serviceName+"\"");

    try

    {

    //判断是否可以恢复

    if((bool)mo["acceptPause"]&&(string)mo["State"]=="Paused")

    mo.InvokeMethod("ResumeService",null);

    }

    catch(ManagementException e)

    {

    strRst =e.Message;

    }

    return strRst;

    }

    // 停止指定的服务

    public string StopService(string serviceName)

    Ҷƪл˵?
  • һƪ使用C#调用外部Ping命令获取网络连接情况
    һƪ使用C#编写的一个定时关机程序