zoukankan      html  css  js  c++  java
  • 让自己的C++程序(非服务程序)运行为一个windows service

    因为项目的一些变化和原因,需要把数据处理的一个后台程序创建为一个windows服务,运行以下命令能创建成功:

    sc create "MyApp Service Name" binPath= "D:/MathxH/Project/SocketS
    ervice/trunk/MyApp/Win32/Release/MyApp.exe" start= auto

    但是因为我的App程序是非服务(non-service)可执行程序,所以在让它运行的时候,却失败了,抛出以下错误:

    error 1053: the service did not respond to the start or control request in a timely fashion 

    追溯其原因,原来是需要程序,写成一个服务可执行程序才能正确运行。

    当然,也有一些工具可以让非服务程序作为windows service来运行,比如NSSM,http://nssm.cc/     它是开源的。由于项目时间原因,本人不想花时间研究它的实现源码了,而且这工具就一个exe,没其他冗余的依赖bin。所以直接可以与项目exe捆绑在一起,作为安装时的一个辅助工具。

    该工具基本的命令行:

    nssm install "Service Name" "exe file path"

    nssm remove "Service Name"

    nssm start "Service Name"
    nssm stop "Service Name"
    nssm restart "Service Name"

    references:
    https://msdn.microsoft.com/en-us/library/40xe80wx(v=vs.80).aspx

    http://stackoverflow.com/questions/3582108/create-windows-service-from-executable

    https://code.msdn.microsoft.com/windowsapps/CppWindowsService-cacf4948/sourcecode?fileId=21604&pathId=2141735795

  • 相关阅读:
    centos 7 安装Telnet并设为开机自启动、开防火墙端口
    cenos 7 中firewalld开放服务端口
    来自鸟哥的lftp客户端软件使用方法
    关闭Linux无用端口
    家用路由器网络设置DMZ区
    Linux中退出循环命令
    shell函数基本概念
    inode节点用尽处理
    xfs格式化、ext4格式化并指定inode区别
    dd备份命令使用
  • 原文地址:https://www.cnblogs.com/foohack/p/5545531.html
Copyright © 2011-2022 走看看