Roll Your Own Windows Service
While it certainly isn’t rocket science, running a daemon as a Windows service can be a hassle. The tools are there, and so is the documentation that accompanies them, but you often need to do some digging. That’s why I’m writing this quick recipe.
In my case, I’m installing the Jetrix TetriNET server as a Windows XP service—what can I say, it’s still fun. Obviously, you can use literally any daemon that you would ordinarily run from a command prompt.
Get the Windows Server 2003 Resource Kit Tools. For Vista users, I presume there’s a Windows Server 2008 package.
As per KB137890, fire up a command prompt and type:
C:\ResKit\InstSrv.exe Jetrix C:\ResKit\SrvAny.exe
Obviously, if you installed the Resource Kit Tools to a different location, you’ll need to update both paths. You may need to put quotes around strings that contain spaces.
Now for the part where we configure the new
SrvAnyservice. Open the Windows Registry Editor and navigate to:HKLM\SYSTEM\CurrentControlSet\Services\Jetrix
Under that key, create a new subkey called
Parameters.In the
Parameterskey, there are three important string-typed values you can define:Application: the binary to invokeAppParameters: the command line arguments for itAppDirectory: the working directory
Jetrix is actually an executable JAR file, so I’m using:
java.exe(relying on the globalPATHenvironment variable)-Djava.library.path=lib
-jar lib/jetrix-launcher-0.2.3.jarC:\Jetrix
And that’s all there is to it. You can now start the service by typing:
sc start Jetrix
To verify that the service is running, use Process Explorer or hit Jetrix’s Web interface.
Yep, this is exactly how I spend my lunch break. If you don’t like it, then you must be more interesting than I am.