Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a window console program named a.exe by VC++ which is running 24 hours a day.
I tried to change this program to windows service program.
But when I have written a code about it as seen my manual, the compiler could not know the variable type of SERVICE_TABLE_ENTRY, or SERVICE_STATUS, etc.

1. What is my main error point even though it is written as in the manual?
2. As another ways to satisfy this purpose, I will make a dialogue with a "Start" button, so if clicking it, the "ShellExecute()" function open the batch file which is including "sc /create a.bat". But this caused an error message about "access denied"....

So both errors are very complicated problems to me, making windows service for a novice is not easy.

Please let me show the simple samples about this.

Thank you in advance.

What I have tried:

More 3 days wasted for this problem.
Posted
Updated 31-Oct-17 22:03pm

1 solution

For examples see A basic Windows service in C++ (CppWindowsService) sample in C++ for Visual Studio 2008[^] and Simple Windows Service in C++[^].

SERVICE_TABLE_ENTRY and SERVICE_STATUS are defined in Winsvc.h which is included by Windows.h. So they should be known when compiling.

sc.exe is the service control manager command line application. It must be executed with sufficient privileges to create, start, and stop services. Creation must be done only once and is usually performed by an installation process (or manually for testing / non-public services using a command shell started as Administrator). When using a normal application that calls ShellExecute to execute sc, that application has to be executed too with sufficient privileges.

Note also that you have to delete the service during development when a previous version has been already created. Not doing so will also result in Access denied errors.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900