Quickly create a Windows service using Windows Service Wrapper

Source: Internet
Author: User

Use Windows Service wrapper to quickly create a Windows service Foreword

Today introduces the use of a gadget. We all know that Windows service is a special kind of application, it has the advantage of being able to run in the background, relatively, it is more suitable for some applications that need to run without too much user intervention, which we call "service"

Writing Windows service is not difficult, especially if you have Visual Studio. But still have a lot of children's shoes feel slightly cumbersome, at the same time, if there are some other programs, we only get an EXE, or a bat, but want to let him run like a service, how to do?

The answer is that you can use one of the following tools, whose name is "Windows Service Wrapper, or WSW."

Basic use of WSW

The general steps to use are:

1. Download the latest version of WSW, put it in any location, and change it to any name you want.

2. Writing an XML file with the same name

3. Installing using the Install command

4. If you want to uninstall, use the uninstall command

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

This project creates a wrapper executable the can is used to the host any executable as a Windows service.

Download

The binaries is available here for download.

Usage

During Your development ...

    1. Take from winsw.exe 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 the files side by side If you deploy your application, because that's how to winsw.exe discovers its configuration.

At runtime ...

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

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

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

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

Deferred File Operations

To the 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's, it's in the same directory as But with a different file extension), and the operation add one line:

    • To move a file, write "Src>dst". If the ' DST ' file already exists it'll be overwritten.

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

Contributions Welcome

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

Configuration file Format Please refer to: https://kenai.com/projects/winsw/pages/ConfigurationSyntax

An example of me is as follows

After running the install, you can see this service in Services.msc

Related knowledge

In the Windows system, there is a special kind of service, they are started with a special program (SVCHOST), as follows

So, what's the matter? Interested children's shoes can refer to http://www.howtogeek.com/howto/windows-vista/what-is-svchostexe-and-why-is-it-running/

On the Linux system, there is also a similar tool (and more powerful), supervisor, interested children's shoes can refer to

Http://supervisord.org/introduction.html

Quickly create a Windows service using Windows Service Wrapper

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.