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.

Mihai Limbăşan
  • 3,081
  • 23
  • 19
Lucas Lindström
  • 193
  • 1
  • 2
  • 7
  • 3
    You should take this question to StackOverflow since it deals with development. – Jeff May 25 '09 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 '09 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 '09 at 00: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. – Lucas Lindström May 26 '09 at 04:57
  • 1
    Definitely seems like a serverfault question to me. – Wayne Koorts May 26 '09 at 20:40

4 Answers4

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" 
Sam Cogan
  • 38,736
  • 6
  • 78
  • 114
  • 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 '09 at 00: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. – Rob Penridge Dec 29 '11 at 18:31
4

Use SRVANY.EXE from Windows * Resource Kit

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

Alex Bolotov
  • 877
  • 3
  • 10
  • 18
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.

David
  • 153
  • 1
  • 6
1

FireDaemon is another option for doing this.

Ryan Bolger
  • 16,755
  • 4
  • 42
  • 64