想在web端程序控制某个service的启动 停止,怎么做?

解决方案 »

  1.   

    try this :Process p = new Process();
    p.StartInfo.FileName = "cmd.exe";
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.CreateNoWindow = false;
    string[] strOutput = new string[2];
    p.Start();
    p.StandardInput.WriteLine("net start yourService");
      

  2.   

    我的服务名为Service Center,exe文件为servicecenter.exe,用上面方法怎么做?我将cmd.exe改为servicecenter.exe,出错:系统找不到指定的文件试用了以下代码:
    ServiceController ctl = new ServiceController();
    ctl.MachineName = "GUOXIN";
    ctl.ServiceName = "Service Center";
    ctl.Start();
    出错:System.ComponentModel.Win32Exception: 拒绝访问。