1,创建,
打开vs.net , 新建一个项目,类型为windows service
2,安装,
installutil service1.exe
installutil /u service1.exe 删除
3,控制
ServiceController sc=new ServiceController(serverName);
sc.start(); sc.stop();sc.continue();
4,传送消息
在service1.cs中 //command must between 128-256
protected override void OnCustomCommand(int command)
{
if (command==130) this.eventLog1.WriteEntry("the 130 service1 stop");
if (command==140) this.eventLog1.WriteEntry("the 140 service1 stop");
}
在控制文件中
ServiceController myController = new ServiceController("service1");
myController.ExecuteCommand(130);
打开vs.net , 新建一个项目,类型为windows service
2,安装,
installutil service1.exe
installutil /u service1.exe 删除
3,控制
ServiceController sc=new ServiceController(serverName);
sc.start(); sc.stop();sc.continue();
4,传送消息
在service1.cs中 //command must between 128-256
protected override void OnCustomCommand(int command)
{
if (command==130) this.eventLog1.WriteEntry("the 130 service1 stop");
if (command==140) this.eventLog1.WriteEntry("the 140 service1 stop");
}
在控制文件中
ServiceController myController = new ServiceController("service1");
myController.ExecuteCommand(130);
博客介绍了Windows Service相关操作。包括在vs.net中新建Windows Service项目进行创建;使用installutil命令进行安装和删除;通过ServiceController类实现启动、停止等控制;还说明了在service1.cs和控制文件中实现消息传送,指定命令范围为128 - 256。

被折叠的 条评论
为什么被折叠?



