• windows服务部署


    1.新建windows服务项目

    2.编辑业务代码

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

     1 using System;
     2 using System.IO;
     3 using System.ServiceProcess;
     4 
     5 namespace WindowsService
     6 {
     7     public partial class Service : ServiceBase
     8     {
     9         public Service()
    10         {
    11             InitializeComponent();
    12         }
    13 
    14         protected override void OnStart(string[] args)
    15         {
    16             System.IO.File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt"), string.Format("{0}我在开始了", DateTime.Now));
    17         }
    18 
    19         protected override void OnStop()
    20         {
    21             System.IO.File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt"), string.Format("{0}我在停止了", DateTime.Now));
    22         }
    23     }
    24 }

    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

  • 相关阅读:
    云服务器数据库连接(初始密码)
    springboot打jar包正常无法访问页面
    JAVA项目启动正常,无法访问
    vs快捷键大全(转)
    Effective C#(3)
    单元测试之道C#版(1)
    单元测试之道C#版(2)
    从零开始复习股票知识
    A new languageGo
    单元测试之道C#版(3)
  • 原文地址:https://www.cnblogs.com/liuxiaoji/p/4779024.html
Copyright © 2020-2023  润新知