有關windows服務的創建,控制
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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.