The Pinged Hobbit

Any one thats been reading my past entries may know I dabble in a little software development here and there. Some times for my own amusement but quite often it’s for a reason relevant to work. Recently we have been developing a new application to talk the network connected devices we use. It constantly polls the devices for fresh information as long as the communication software is running somewhere on the network and adds this information to the database.

The idea being that the software runs in a client/server set up with one central machine constantly running the communications software. The communication software was initially developed to run as a normal windows process. This was ok initially, the software was usually running on one PC and only needed to be pulling data in when someone was using that PC. Things got tricky once we started installing on to multiple PC’s.

With it running as a process it meant that what ever machine was running the comms software had to be always logged in other wise the process was shut down. A lot of people are not comfortable with always having their server logged in so this became a problem. The obvious way around this was to have the comms running as a windows service. A windows service does not need the machine to be logged in for it to be running, it will run as soon as the PC is turned on effectively. Much easier than relaying on some one remembering to log the machine on as well.

Doing a Google search on making a process run as a service will pull up a lot of links related to two pieces of the windows server development kit, one called srvany and the other instsrv, or the dos command sc. These can be used to create a service from a process. I tried both of these approaches out, and while I could get them to run my process for me, I could not use them in a way that could be embeddded in my installation package so that the paths to the programs could be updated if changed during the install.

I toyed around for a few months on the various ways and tried making a bat file and compiling it into a exe but this still didn’t all variations in the install location. Then quite by mistake I stumbled upon a little utility called xyntservice. Xyntservice is an open source tool that runs as a windows service and can then run/stop other programs as a process without a use being logged in to the machine. All that is required is to modify an entry in the accompanying ini file and then small dos command will install the xyntservice on the maching and bingo your process will run with no one logged in.

It is possible to write a Windows service as a Windows program, but here I am proposing a much easier solution. I have included with this article the source code for a simple Windows service program that can start and shut down other programs. All you need to do is install this service and modify the INI file. Here are the advantages of using this simple Windows service:

* It can start up to 127 programs of your choice. The started programs behave like Windows services in that they will be running in the background without the user having to log into the machine.
* A user cannot kill the programs started by this service without proper privilege unless, of course, the machine is shutdown.
* You can test and debug your programs outside of the Windows service. For example, you can run your programs in the Visual Studio debugger and step into the source code to find bugs, etc. When it is “bug free,” you can deploy it in production, starting it from the Windows service.
* You can run a broad range of programs using this service, including .NET programs, VB scripts and batch files. This service has been used by the open source world to run numerous Java programs.

Code Project xyntservice page

Using xyntservice I could put the programs files anywhere during the installation, then just have the installer update the xyntservice ini file with the location of them (I set the xyntfiles to always be in the windows installation folder). I then had a nice simple way of installing a service that was easy to control. As an added bonus in some circumstances it is possible to still have the process run a user interface for my communications software if I need it, something that cant be done with a service created by srvany.

Its quite possible that there are other utilities out there that do this in a better way, but xyntservice fits my needs wonderfully and I don’t see the reason for looking anywhere else. I’m sure others might have their own suggestions thought

Leave a Reply

Proudly powered by WordPress. Theme developed with WordPress Theme Generator.
Copyright © The Pinged Hobbit. All rights reserved.