pwnt.be

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.

  1. Get the Windows Server 2003 Resource Kit Tools. For Vista users, I presume there’s a Windows Server 2008 package.

  2. 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.

  3. Now for the part where we configure the new SrvAny service. Open the Windows Registry Editor and navigate to:

    HKLM\SYSTEM\CurrentControlSet\Services\Jetrix
  4. Under that key, create a new subkey called Parameters.

  5. In the Parameters key, there are three important string-typed values you can define:

    • Application: the binary to invoke
    • AppParameters: the command line arguments for it
    • AppDirectory: the working directory

    Jetrix is actually an executable JAR file, so I’m using:

    • java.exe (relying on the global PATH environment variable)
    • -Djava.library.path=lib
      -jar lib/jetrix-launcher-0.2.3.jar
    • C:\Jetrix
  6. And that’s all there is to it. You can now start the service by typing:

    sc start Jetrix
  7. 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.

Post a Comment

This contraption supports Gravatar, as well as Markdown with SmartyPants. If none of that made sense to you, feel free to ignore it and start typing.

  • :)
  • :D
  • ;)
  • :-O
  • :P
  • :@
  • :$
  • :S
  • :(
  • :'(
  • :|
  • :-#
  • 8-|
  • ^o)
  • :-*
  • +o(
  • :^)
  • *-)
  • 8-)
  • |-)
Disorientation
Continuity
Tangentiality
Retributions
The HTC Desire Kicks the HTC Legend’s Ass
Tom, Tim, Tom, Tim, Tim, Tom
Google Chrome Still Sucks
smeezekitty, Tim, milosh
Automating OpenVPN Connection on Windows XP
Tim, Geb, 12vpn, Tim, neecom
Bizar Hairdressing & Beyond
Ruxi, Wim, Tim, Sarina, Lies, Lynn, erwin, Ano, Frederick, Jacqueline, Wazaaa, Tim, Rebecca, Charlie
Pidgin to Adium Emoticon Theme Converter
Tim, peter
Colophonics