首页 > Windows开发 > 详细

windows服务部署

时间:2015-09-02 18:37:18      阅读:364      评论:0      收藏:0      [点我收藏+]

1.新建windows服务项目

技术分享

2.编辑业务代码

我这里只写2句记录文本的测试代码

技术分享
using System;
using System.IO;
using System.ServiceProcess;

namespace WindowsService
{
    public partial class Service : ServiceBase
    {
        public Service()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            System.IO.File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt"), string.Format("{0}我在开始了", DateTime.Now));
        }

        protected override void OnStop()
        {
            System.IO.File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt"), string.Format("{0}我在停止了", DateTime.Now));
        }
    }
}
View Code

3.添加安装程序

技术分享

 

4.设置ProjectInstaller属性


技术分享

技术分享

技术分享

这2个按照图上面设置即可

下面分别导入bat文化

InstallUtil.bat(安装)

WindowsService.exe 程序名称
TestService 上面设置的服务名称 ServiceName
InstallUtil WindowsService.exe
net start TestService
pause

startService.bat(启动服务)

net start TestService
pause

stopService.bat(停止服务)

net stop TestService
pause

UnIntall.bat(卸载)

installutil /u WindowsService.exe
pause

把这个4个文件放在根目录下面设置始终复制即可

还有一个文件InstallUtil.exe 也需要设置始终复制
做完这些操作然后生成一些程序 到bin目录双击InstallUtil.bat安装即可

 

下载demo

转:http://www.cnblogs.com/liuxiaoji/p/4779024.html

 

windows服务部署

原文:http://www.cnblogs.com/love201314/p/4779156.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!