一、安装服务:
InstallService
二、卸载windows服务:
UnInstallService
三、判断window服务是否存在:
ServiceIsExisted
private bool ServiceIsExisted(string serviceName)
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController s in services)
{
if (s.ServiceName == serviceName)
{
return true;
}
}
return false;
{
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController s in services)
{
if (s.ServiceName == serviceName)
{
return true;
}
}
return false;
四、启动服务:
StartService
五、停止服务:
StopService
注:手动安装window服务的方法:
在“Visual Studio 2005 命令提示”窗口中,运行:
安装服务:installutil servicepath
卸除服务:installutil /u servicepath
安装
@echo off
echo 正在安装PService服务,请稍等......
installutil WindowsService.exe
net start Service
echo. & pause
卸除
@echo off
net stop PlusNetService
installutil /u WindowsService.exe
echo. & pause
MSDN资料
http://msdn.microsoft.com/zh-cn/library/system.management.managementscope.aspx?TPSecNotice