码迷,mamicode.com
首页 > Windows程序 > 详细

windows 服务 安装、卸载

时间:2017-02-18 16:44:30      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:注意   cdc   生成   path   logs   技术分享   microsoft   debug   des   

1、新建项目 选中windows服务

技术分享

 

2、添加安装程序

技术分享

 

 3、修改安装代码

技术分享

        ServiceProcessInstaller processInstall;
        ServiceInstaller serviceInstall;
        public ProjectInstaller()
        {
            this.processInstall = new ServiceProcessInstaller();
            this.serviceInstall = new ServiceInstaller();

            processInstall.Account = ServiceAccount.LocalSystem;
            this.serviceInstall.ServiceName = "ABC_TaskService";
            this.serviceInstall.Description = "ABC_Description";
            this.Installers.Add(this.serviceInstall);
            this.Installers.Add(this.processInstall);
        }

  

4、重新生成项目

5、新建bat文件(安装服务.bat)

@ECHO OFF

REM The following directory is for .NET1.1
set DOTNETFX=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX%

cdcd "G:\WindowsServiceTest\WindowsServiceTest\bin\Debug"
echo 正在安装 测试服务
echo ---------------------------------------------------

InstallUtil /i WindowsServiceTest.exe

sc config "ABC_TaskService" start= auto

Net Start "ABC_TaskService"

echo ---------------------------------------------------

pause

  注意:

          1、cd "G:\WindowsServiceTest\WindowsServiceTest\bin\Debug"  路径为项目的路径

          2、InstallUtil /i WindowsServiceTest.exe 其中WindowsServiceTest为项目重新生成的文件名称

          3、sc config "ABC_TaskService" start= auto 其中ABC_TaskService为第三步为服务起的名称

          4、执行bat文件时一定要在管理员:命令提示符中操作 否则会错(无法打开计数机.上的服务控制管理器,拒绝访问等错误)

技术分享

 

    技术分享

 

 6、新建bat文件(卸载服务.bat)

@ECHO OFF

REM The following directory is for .NET1.1
set DOTNETFX=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set PATH=%PATH%;%DOTNETFX%

cdcd "G:\WindowsServiceTest\WindowsServiceTest\bin\Debug"

echo 正在卸载 测试服务
echo ---------------------------------------------------

InstallUtil /U WindowsServiceTest.exe

echo ---------------------------------------------------

pause

  

技术分享

 

安装服务.bat下载

卸载服务.bat下载

windows 服务 安装、卸载

标签:注意   cdc   生成   path   logs   技术分享   microsoft   debug   des   

原文地址:http://www.cnblogs.com/xiao-sheng/p/6413384.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!