7

How can I turn a given normal application into a Windows service under Windows XP?

EDIT: This is a server application, so it has no GUI and does not require any input or output.

5
  • 3
    You should take this question to StackOverflow since it deals with development.
    – Jeff
    May 25, 2009 at 22:14
  • 3
    Not really. Running programs as a system service is fairly sysadmin-y, and as the answers below show, don't involve what we'd call programming or development.
    – jldugger
    May 25, 2009 at 22:40
  • 2
    You can't turn any application into a Windows Service. It has to implement specific routines so SC knows how to communicate with it. Sure you can create the service given the instructions below but that does NOT mean it will run. ex. do this on Windows XP sc.exe create "Foo Service" binPath= "%SystemRoot%\system32\notepad.exe" this creates fine but then try to run it SC Start "Foo Service" [SC] StartService FAILED 1053: The service did not respond to the start or control request in a timely fashion.
    – Jeff
    May 26, 2009 at 0:57
  • @JD (first comment) - Which is something I could not possibly have known beforehand. It doesn't -seem- like a StackOverflow question to me, and it probably won't to other people either. (second comment) - Why not post that comment as an answer? It definitely contains useful information. May 26, 2009 at 4:57
  • 1
    Definitely seems like a serverfault question to me. May 26, 2009 at 20:40

4 Answers 4

12

You can use SC to create user defined services. This command will create a service:

sc.exe create "Service Name" binPath= "C:\Your Program.exe"

Note there must be a space between binpath= and the program location.

To Delete the service use:

sc.exe delete "Service Name" 
2
  • 1
    Putting a normal program into use as a service like this is asking for trouble. If it is a gui program, forget it. You'll never see the screen. If it's a console program it cannot rely on the user to enter anything and no output sent to the screen will be seen. As JD suggested, asking on StackOverflow may yield better long term results.
    – Brad Bruce
    May 26, 2009 at 0:54
  • Use this answer in conjunction with Oleksandr's SRVANY.EXE answer below. This will allow you to start/stop the application like a service from the Windows services manager. Dec 29, 2011 at 18:31
4

Use SRVANY.EXE from Windows * Resource Kit

For Cygwin applications Use cygrunsrv (NT/W2K service initiator)

2

Also, once you successfully started your normal application as a service, I would suggest to test how the application behaves when you log off.

Some applications (old ones?) don't like receiving the message that is sent when logging of or shutting down the computer.

1

FireDaemon is another option for doing this.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .