I want to make an application in c++ which will run periodically. much like an windows service. Is it possible to create a windows service in C++. If yes how?
Any tutorial for this?
EDIT: How can I create an installer for the Windows service?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As indicated in another answer, you need to create a normal C++ program (starting with
main), and callStartServiceCtrlDispatcherWin32 API to tell Windows that you want to run this program as a service. Some information on this function can be found in MSDN.Additionally, you’ll need a mechanism to install your service so that it appears in Windows Service Control Panel. And of course, an uninstall feature should also be provided. Typically, all the three functions (i.e., install, uninstall and run) are handled in a single executable. The difference in these three is indicated via command line parameters.
You’ve not indicated what version of VC++ you are using. If you are going with managed .NET code, then it’s quite easy as Windows Service template is prebuilt into Visual Studio.
However, if you are going with VC++ 6 (or 100% unmanaged code), then you need to know a lot of low level details. Further choices depend on your know-how of ATL or MFC (if you are going with older versions of the compiler/ runtime).
This might be a good tutorial on creating Windows Services using C++.