Go to my github

Win7开发系列: windows服务操作基础

一、安装服务:

 

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;

 

四、启动服务:

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.managementobject.getmethodparameters(v=VS.80).aspx

http://msdn.microsoft.com/zh-cn/library/system.management.managementscope.aspx?TPSecNotice

http://msdn.microsoft.com/zh-cn/library/system.serviceprocess.servicecontroller_members(v=VS.80).aspx

posted @ 2011-07-12 18:38  峡谷少爷  阅读(450)  评论(0编辑  收藏  举报