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.
- 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
RWWinService to run my fossil source repositories in the background. The following configuration is how I make that happen:
<add key="CheckProcessSeconds" value="30"/>
<add key="PauseStartMs" value="1000"/>
<add key="PauseEndMs" value="1000"/>
<Arguments>server --port 8080 c:\rev\fossil\fossil.fossil</Arguments>
<Arguments>server --port 8081 c:\rev\fossil\rwwinservice.fossil</Arguments>
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.
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 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
RWWinService leverages the SimpleService framework, so the following command line options are available:
PS C:\rev\bin> RWWinService -help
= 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.
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!
- March 2010 - Initial submission