首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎样通过程序启动window服务解决方法

2012-01-28 
怎样通过程序启动window服务我现在做了一个windows服务,我还需要做一个管理此服务的程序,现在的问题是怎样

怎样通过程序启动window服务
我现在做了一个windows服务,我还需要做一个管理此服务的程序,现在的问题是怎样通过程序启动和停止服务!

[解决办法]
ServiceController sc = new ServiceController( "ServiceName ");
if (sc.Status == ServiceControllerStatus.Stopped)
{
sc.Start();
sc.Stop();
}

[解决办法]
ServiceController sc = new ServiceController( "ServiceName ");
if (s == "START " && sc.Status.Equals(ServiceControllerStatus.Stopped))
{
sc.Start();
}
if (s == "STOP " && !sc.Status.Equals(ServiceControllerStatus.Stopped))
{
sc.Stop();

热点排行