前言

今天介绍一个小工具的使用。我们都知道Windows Service是一种特殊的应用程序,它的好处是可以一直在后台运行,相对来说,比较适合一些需要一直运行同时不需要过多用户干预的应用程序,这一类我们称之为“服务”吧

编写Windows Service其实是不难的,尤其是如果有Visual Studio的话。但是仍然是有不少童鞋觉得略显繁琐,同时,如果有一些其他的程序,我们只拿到一个exe,或者一个bat,但又想让他象服务一样运行,怎么办呢

答案就是可以使用如下的一个工具,它的名称就叫:Windows Service Wrapper,简称WSW。

wsw的基本使用

一般的使用步骤是:

1. 下载wsw的最新版本,放在任意的位置,修改成你想要的任何名字

2.编写一个同名的xml文件

3.使用Install命令进行安装

4.如果想要卸载,则使用Uninstall命令

https://kenai.com/projects/winsw/pages/Home

This project creates a wrapper executable that can be used to host any executable as an Windows service.

Download

The binaries are available here for download.

Usage

During your development...

  1. Take winsw.exe from the distribution, and rename it to your taste (such as myapp.exe)
  2. Write myapp.xml (see Configuration Syntax for more details)
  3. Place those two files side by side when you deploy your application, because that's how winsw.exe discovers its configuration.

At runtime...

  • To install a service, run myapp.exe install
  • To start a service, run myapp.exe start
  • To stop a service, run myapp.exe stop
  • To restart a service, run myapp.exe restart
  • To uninstall a service, run myapp.exe uninstall

When there's a problem, these commands also report an error message to stderr. On a successful completion, these commands do no produce any output and exit with 0.

In addition, you can also run myapp.exe status to have it print out the current status of the service to stdout. Again, any error encountered during the processing would cause output to be reported to stderr.

All these commands use the same set of exit code to indicate its result.

Deferred File Operations

To support self updating services, winsw offers a mechanism to perform file operations before a service start up. This is often necessary because Windows prevents files from overwritten while it's in use.

To perform file operations, write a text file (in the UTF-8 encoding) at myapp.copies (that is, it's in the same directory asmyapp.xml but with a different file extension), and for each operation add one line:

  • To move a file, write "src>dst". If the 'dst' file already exists it will be overwritten.

The success or failure of these operations will be recorded in the event log.

Contributions Welcome

If you are interested in joining the project, let me know. I'm always interested in more committers.

配置文件的格式请参考:https://kenai.com/projects/winsw/pages/ConfigurationSyntax 

我的一个例子如下

运行install后,在services.msc中可以看到这个服务

相关知识

在Windows系统里面,还有一类特殊的服务,他们都是用一个特殊的程序启动的(svchost),如下

那么,这又是怎么一回事情呢?有兴趣的童鞋可以参考  http://www.howtogeek.com/howto/windows-vista/what-is-svchostexe-and-why-is-it-running/

在Linux系统上面,也有一个类似的工具(而且更加强大),supervisor,有兴趣的童鞋可以参考

http://supervisord.org/introduction.html

使用Windows Service Wrapper快速创建一个Windows Service的更多相关文章

  1. 使用Windows Service Wrapper快速创建一个Windows Service 如nginx

    前言 今天介绍一个小工具的使用.我们都知道Windows Service是一种特殊的应用程序,它的好处是可以一直在后台运行,相对来说,比较适合一些需要一直运行同时不需要过多用户干预的应用程序,这一类我 ...

  2. C#创建一个Windows Service

    Windows Service这一块并不复杂,但是注意事项太多了,网上资料也很凌乱,偶尔自己写也会丢三落四的.所以本文也就产生了,本文不会写复杂的东西,完全以基础应用的需求来写,所以不会对Window ...

  3. [翻译] 使用 .NET Core 3.0 创建一个 Windows 服务

    原文: .NET Core Workers as Windows Services 在 .NET Core 3.0 中,我们引入了一种名为 Worker Service 的新型应用程序模板.此模板旨在 ...

  4. 为MongoDB创建一个Windows服务

    一:选型,根据机器的操作系统类型来选择合适的版本,使用下面的命令行查询机器的操作系统版本 wmic os get osarchitecture 二:下载并安装 附上下载链接 点击安装包,我这里是把文件 ...

  5. 创建一个Windows服务程序与实现定时器效果

    1.创建一个Windows服务程序 一.   新建Window服务项目 二.   添加安装程序 三.   配置服务属性 四.   编写定时器代码 publicpartialclassService1 ...

  6. Step by Step 创建一个WCF Service

    原创地址:http://www.cnblogs.com/jfzhu/p/4025448.html 转载请注明出处 (一)创建WCF Service (1)创建WCF Service类库 创建一个Cla ...

  7. ASP.NET Core模块化前后端分离快速开发框架介绍之2、快速创建一个业务模块

    源码地址 GitHub:https://github.com/iamoldli/NetModular 演示地址 地址:https://nm.iamoldli.com 账户:admin 密码:admin ...

  8. Step by Step 创建一个 Web Service

    原创地址:http://www.cnblogs.com/jfzhu/p/4022139.html 转载请注明出处 (一)创建Web Service 创建第一个项目,类型选择ASP.NET Empty ...

  9. 通过beego快速创建一个Restful风格API项目及API文档自动化

    通过beego快速创建一个Restful风格API项目及API文档自动化 本文演示如何快速(一分钟内,不写一行代码)的根据数据库及表创建一个Restful风格的API项目,及提供便于在线测试API的界 ...

随机推荐

  1. Linux 系统查看物理内存使用率的命令脚本,以百分比形式输出。

    想监视系统内存?好像是没法直接得到现成的百分比的,自己取值计算一下吧 totalmem=`free -m | grep 'Mem' | awk '{print $3}'` usedmem=`free ...

  2. 2014 summer training总结篇

    还有一周暑期集训就要结束了,从7月份结束军训到现在一个多月的时间,收获也是有的只不过与之前预想的相比显得十分微薄. 无论是前两天的两场个人赛还是之前的组队赛自己始终是在ranklist的后半部分.一开 ...

  3. 如何给GridView添加网格

    如何给gridview的单元格加上分割线 原文链接:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2013/1227/1582.html ...

  4. angularJs 指令的理解

    指令: 可以把指令理解成为特定的DOM 上运行的函数,指令扩展了这个元素的功能: 例如:ng-click--在DOM元素上绑定了一个click事件的监听,并在监听到事件时运行angular表达式 自定 ...

  5. 初探SQL注入

    1.1注入语句(通过时间注入函数) 数据库名称 localhost:8080/ScriptTest/userServlet?username='union SELECT IF(SUBSTRING(cu ...

  6. The Solution of UESTC 2016 Summer Training #1 Div.2 Problem C

    Link http://acm.hust.edu.cn/vjudge/contest/121539#problem/C Description standard input/output After ...

  7. Linux上传下载文件快捷命令

    远程链接Linux(如SecrueCRT),要上传文件很下载文件到Linux服务器,只需要使用sz或者rz命令即可快速下载和上传文件了. 使用方法: 1.首先确保Linux服务器系统中安装了lrzsz ...

  8. 七种机器内部排序的原理与C语言实现,并计算它们的比较次数与移动次数。

    内部排序是指待排序列完全存放在内存中所进行的排序过程,适合不太大的元素序列. 排序是计算机程序设计中的一种重要操作,其功能是对一个数据元素集合或序列重新排列成一个按数据元素某个相知有序的序列.排序分为 ...

  9. Asp.Net Core 发布和部署(Linux + Jexus )

    前言 在上篇文章中,主要介绍了 Dotnet Core Run 命令,这篇文章主要是讲解如何在 asp.net core 中对我们的已经完成的程序进行发布和部署. 有关如何使用 Nginx 进行部署, ...

  10. 基于Redis的开源分布式服务Codis

    Redis在豌豆荚的使用历程--单实例==>多实例,业务代码中做sharding==>单个Twemproxy==>多个Twemproxy==>Codis,豌豆荚自己开发的分布式 ...