views:

100

answers:

3

Hello all,

Our company just completed a Win 32 Application project, and we have a executable program and it works fine in Windows. Now we have to run it as a windows service under Network account. I am pretty new to Windows Service, so please advice, what should I do to transform this program to a Windows Service? Thank you!

+2  A: 

If you mean that you want to run your application as a windows service, there is a utility in Windows Resource Kits. It's name is srvany.exe and you can find documentation about it here: http://search.microsoft.com/search/results.aspx?st=b&View=en-us&s=1&c=0&qu=137890

Srvany.exe can be downloaded as part of Windows Server 2003 Resource Kit Tools here: http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

alemjerus
+3  A: 

If by "Win32 Application project" you mean "GUI program", then do not run that as a service. Otherwise, here's what you need to do:

  • Register a service control handler using RegisterServiceCtrlHandler as soon as your program starts. This is required so you can handle the start and stop events. If you do not do this the service manager will kill your process because it thinks it's not a real service.
  • If you have an installer, you can use the sc command to create the service. For example: sc create MyService binPath= "C:\PathToExe\MyService.exe" type= own start= auto.
  • Alternatively you can call CreateService if you have code to do this.
wj32
A: 

Hi Ray.

Srvany.exe is a fine, free solution (as described by alemjerus), but please check out AlwaysUp if you are working in a professional environment and need a robust/advanced feature set.

Good luck!

CoreTech