站内搜索
分类列表
本类阅读排行
本类推荐文章
广告
利用vs.net快速开发windows服务
作者: 来源: 点击: 日期:2007-11-21 10:37:39
// Toggle the Telnet service -
// If it is started (running, paused, etc), stop the service.
// If it is stopped, start the service.
ServiceController sc = new ServiceController("Telnet");
Console.WriteLine("The Telnet service status is currently set to {0}",
sc.Status.ToString());
if ((sc.Status.Equals(ServiceControllerStatus.Stopped))
(sc.Status.Equals(ServiceControllerStatus.StopPending)))
{
// Start the service if the current status is stopped.
Console.WriteLine("Starting the Telnet service...");
sc.Start();
}
else
{
// Stop the service if its status is not set to "Stopped".
Console.WriteLine("Stopping the Telnet service...");
sc.Stop();
}
// Refresh and display the current service status.
sc.Refresh();
Console.WriteLine("The Telnet service status is now set to {0}.",
sc.Status.ToString());
总结
最近公司要我做这个,我看了相关的文章,便整理了一下.
实践的时候也出现了服务不执行操作的现象,希望大家一起共同探讨一下,相互学习.
利用vs.net快速开发windows服务 评论
