Click here to Skip to main content
Licence CPOL
First Posted 2 Mar 2010
Views 3,829
Downloads 99
Bookmarked 12 times

RWWinService - A Simplified .NET 3.5 branch of XYWinService

By | 2 Mar 2010 | Article
A branch/fork of Xiangyang Liu's XYNTService/XYWinService

Introduction

This project is my personal branch of Xiangyang Liu's XYWinService.

In this version, I leverage my own SimpleService project to add features and solve a few minor annoyances.

New Features

  • Upgraded the solution to VS2008
  • Simplified configuration using app.config
  • Improved install/uninstall service support
  • Console mode - for simplified debugging
  • Logging to application event log
  • More command line options

Configuration

I use RWWinService to run my fossil source repositories in the background. The following configuration is how I make that happen:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="Process" 
      type="System.Configuration.IgnoreSectionHandler" />
  </configSections>
  <appSettings>
    <add key="CheckProcessSeconds" value="30"/>
    <add key="PauseStartMs" value="1000"/>
    <add key="PauseEndMs" value="1000"/>
  </appSettings>
  <Process>
    <FilePath>c:\rev\bin\fossil.exe</FilePath>
    <Arguments>server --port 8080 c:\rev\fossil\fossil.fossil</Arguments>
    <WorkingDir>c:\rev\bin</WorkingDir>
    <Restart>Yes</Restart>
  </Process>
  <Process>
    <FilePath>c:\rev\bin\fossil.exe</FilePath>
    <Arguments>server --port 8081 c:\rev\fossil\rwwinservice.fossil</Arguments>
    <WorkingDir>c:\rev\bin</WorkingDir>
    <Restart>Yes</Restart>
  </Process>
</configuration>

There is a little bit of magic going on in this config file. Normally, the ConfigurationManager class expects to see only the appSettings element in the configuration, and it will throw an exception if unexpected elements are present. The configSections element lets you tell the ConfigurationManager class to ignore elements named Process and their children via the System.Configuration.IgnoreSectionHandler. Once that is done, you can parse the Process elements yourself in code. Alternatively, you could write your own SectionHandler, but I leave that to you. This gives us a simple, single configuration file.

The three appSettings keys are pretty much self-explanatory, and the Process elements are exactly the same as in XYWinService. I deprecated several configuration items that were available in XYWinService, most notably the RunAs element. This project assumes that the service will run as ServiceAccount.LocalSystem, and there is no configuration option that exposes this.

The Manifest

The manifest is the glue that makes it all come together. One line in particular configures the service to invoke the Vista/Windows7 UAC.

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Managing the Service

The RWWinService leverages the SimpleService framework, so the following command line options are available:

PS C:\rev\bin> RWWinService -help
= usage:
=   RWWinService -install   == install service
=   RWWinService -uninstall == uninstall service
=   RWWinService -start     == start service
=   RWWinService -stop      == stop service
=   RWWinService -status    == get the current status of the service
=   RWWinService -console   == run in console mode
=   RWWinService -help      == show this help message

Using these command-line switches, you can install and uninstall the service without using InstallUtil.exe. Also, you can start and stop the service once it is installed. The -status switch will tell you if the service is installed, started, or stopped.

Conclusions

I've been using this service for several months now without any problems. I think you will find the command-line interface saves you time. I am very much indebted to Xiangyang Liu for his original contribution; functionally, this branch of XYWinService provides the same basic feature set, only simplified and refactored. Please don't hesitate to notify me of bugs or oversights. Enjoy!

History

  • March 2010 - Initial submission

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

ron wilson

Software Developer (Senior)
Harris Corporation
United States United States

Member

I'm your huckleberry.
 
Check out more beards here.



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 2 Mar 2010
Article Copyright 2010 by ron wilson
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid