• dotNetCore创建Windows服务程序并安装服务


    一、创建控制台程序

    二、在项目中添加新建项,选择Windows服务类型。

    此时会出现一个错误提示,这是因为尚未添加windows服务控制引用造成的。

    三、添加Nuget包,System.ServiceProcess.ServiceController。

    添加完成后错误提示就消失了。

    四、更改main方法。

    using System;
    using System.ServiceProcess;
    
    namespace test
    {
        class Program
        {
            static void Main(string[] args)
            {
                ServiceBase[] services = new ServiceBase[] { new Service1() };
                ServiceBase.Run(services);
            }
        }
    }

    五、将程序发布为可执行文件。

    点击编辑,将部署模式改为独立。

    发布。

    根据配置情况,在相应的目录内(例如:binRelease etcoreapp2.2win-x86)即可看到可执行文件。

    六、使用sc命令将可执行文件安装为服务。

    安装服务:sc create testservice binpath="D:Working est estinRelease etcoreapp2.2win-x86 est.exe"

    查询服务:sc query testservice

    启动服务:sc start testservice

    停止服务:sc stop testservice

    卸载服务:sc delete testservice

  • 相关阅读:
    sql server 2008 express 使用ip登陆 error:40 错误:2
    C#将Enum枚举映射到文本字符串
    Qt 自定义事件
    constexpr-C++11
    C++11 Lambda表达式(匿名函数)
    Qt5-调试器安装
    Qt5之坐标系统
    八大排序算法总结
    Qt之类反射机制
    Qt5之反射机制(内省)
  • 原文地址:https://www.cnblogs.com/tianjiuyi/p/11095964.html
Copyright © 2020-2023  润新知