Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I start my web server as web service on Windows XP. How it was done is described here

My web server is coded in ruby/sinatra and I start it C:\Ruby187\bin\ruby c:\web\web2.rb. That code the service too. Manually I stop the web server by pressing CTRL+C in the dos window if started from command line.

I admit that my ruby code is not 'specially written software' to be a service. But I'd like to know if I can shut it down somehow when I click stop button to this service.

How can I stop the server now as it started via service? I found out that I can stop it via taskkill /f /t /im ruby.exe

Is there any way I can use the MMC stop service function to stop the web server?

I call the web server directly like shown in the picture click here to read the text in the picture.

enter image description here

share|improve this question
What is the batch file to start the Ruby server? Taskkill may not be the best way since it does just that: Kills the task, not really shutting it down cleanly. If I can see how you start it, I may be able to tell you how to stop it. I will have to look at it in the morning though...very late here. – KCotreau Jun 24 '11 at 5:19
That doesn't look like a Windows Service, these are applications specially written to be a service (installed as a service, using specific APIs to communicate with the Service Control Manager (SCM)). When something is a service is will appear in the services MMC snapin and can be controlled by the APIs the snapin uses (eg. sc.exe command line tool). – Richard Jun 24 '11 at 8:01
@Richard: To Windows, it is a service - srvany takes care of the SCM communication. – grawity Jun 24 '11 at 8:32

The Stop button sends a "Stop service" control to the service's main program – in this case it's srvany. The rest is up to that program. And it appears that srvany will simply ignore the control.

It seems that the version of srvany for Windows NT 4.0 does kill its immediate children – you can get it from Microsoft.

It is possible to write a real Windows service that would stop your Ruby program nicely – for example, using Python's win32serviceutil. (There doesn't appear to be any Ruby module to interface with Windows, unfortunately.)

From command line or batch scripts, this will do the same as the Stop button:

  • sc stop <name>

  • net stop <name>

Programmatically, you need to call OpenSCManager(...), OpenService(...), then ControlService(..., SERVICE_CONTROL_STOP).

share|improve this answer

You must log in to answer this question.

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