Windows Service Questions

I have some questions about Windows Services. I have done a lot of searching but cannot seem to find the answers so I am hoping someone here can help. I have written an app that runs fine as a daemon in Linux, but want to implement it as a Service in Windows. The program needs to run continually in the background. That part works fine in Linux. The problem comes when I try to create this as a Windows Service.

  1. In the Linux daemon version, it runs in a while loop until a boolean flag is changed. Unless it is signaled to exit (I am using signal handlers to manage this for Linux), the flag doesn’t get set to cause it to exit, therefore creating an otherwise endless loop. I am also using the “Call Daemonize” statement with compiler directives if the executable is for Linux. For Windows, I go into the same loop but do not call daemonize. Is that correct?

  2. I looked at the Empty Service template and it appears that the only thing I would need to do to my existing console app to make it a service is change the App.Super to “Service Application” as well as define code for the other App Event Handlers such as Resume, Paused, Stopped, Run, etc. Is that correct? Unfortunately, that doesn’t seem to work for me. As a console app, the daemon runs in the “endless” loop, but when I change its super to Service Application and re-compile, the program exits immediately.

  3. What should be the behavior of a Windows Service executable? If it is run from the command line should it loop or return immediately?

  4. I want this to eventually be a part of a setup program (using Inno Setup). Would it be better to have command line arguments “install” and “uninstall” which use a Real Basic library to setup the service in Windows and remove it if uninstall is called? Or would it be better to use a library within Inno Setup? This is more of a best practice type of question assuming I get the service to work at all.

Again, I appreciate any help with the questions. I am just new to developing Windows Services and am having difficulty finding answers to these questions and my typical trial-and-error approach of experimentation doesn’t seem to be providing the answers I need.

Try:

http://www.google.com/search?safe=off&client=ms-android-verizon&source=android-home&site=webhp&source=hp&ei=CZjNUpzpC8f7rAHIxoHYBw&q=windows+create+service+from+command+line&oq=windows+create+service+fro&gs_l=mobile-gws-hp.1.3.0l2j0i22i30l3.3437.14113.0.15557.27.27.0.21.21.0.286.3607.11j12j4.27.0....0...1c.1.32.mobile-gws-hp..0.27.1388.2NYG2VOxWuU

Create services either using the built - in command line tools or by creating the appropriate registry entries and having the user restart their system.

Yes

It should loop until closed.

In the Empty Service Template there are comments to indicate a loop is not necessary. It is necessary to create an event loop in the App.Run Event.

Do
Doevents
Loop

on windows, go to command prompt and put this

sc create yourservicename binpath= yourpathname

Thanks everyone for the responses. Been covered in work and just haven’t had a chance to say thanks until now. I was able to get the service going. I really appreciate the replies!