繁体   English   中英

停止和启动.net Windows服务

[英]Stopping and starting .net windows service

我在App服务器1上有一个.Net Windows服务。通过此服务,我需要以编程方式启动和停止在App服务器2上安装另一个.Net Windows服务。如何实现此目的?

谢谢阅读。

这是您需要做的概述。

System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController();
sc.ServiceName = "service name";
sc.MachineName = ".";// for local.  use windows machine name here for a remote service
sc.Start();
TimeSpan ts = new TimeSpan(0, 0, 0, 3, 0); // 3 sec
sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, ts);
if (sc.Status == System.ServiceProcess.ServiceControllerStatus.Running)
    Console.WriteLine("started");
else
    Console.WriteLine("failed to start");

查看MSDN ServiceController信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM