B-Abbasi
B-Abbasi

Reputation: 823

Install and Run Windows Service in C++

I am working on windows services for the first time and after some effort I am now able to Install and unistall a service programatically in C++, I have found many tutorials which guide on how to deal with ServiceMain and ServiceControlHandler functions. Problem is that there is no tutorial which shows that first we install a service and then in the same program apply ServiceMain and ServiceControlHandler functions.

In short I am trying to integrate both functionalities in the same code but it is not working.

Here are some links I have followed

http://www.codeproject.com/Articles/499465/Simple-Windows-Service-in-Cplusplus

http://www.devx.com/cplus/Article/9857/0/page/2

http://msdn.microsoft.com/en-us/library/ms683500(v=vs.85).aspx

my source code is almost exact copy of above examples except that before creating SERVICE_TABLE_ENTRY and calling StartServiceCtrlDispatcher(ServiceTable) I have called the function which Installs the service.

The service Installs correctly but never starts running, infact ServiceMain is never called.

Environment: Windows 7 64-bit Lnaguage C++ Visual Studio 2008

Upvotes: 3

Views: 10883

Answers (1)

Jerry Coffin
Jerry Coffin

Reputation: 490108

At least based on the code you've linked, you have a ServiceMain, and (presumably in main) you call CreateService.

The step you seem to be missing is a call to StartService after you call CreateService.

Upvotes: 3

Related Questions