简体   繁体   中英

C++ Windows Service Error 1063

Trying to develop my first windows service, and I'm debugging in windows 7 MS VC++ 10.0. As soon as it calls, StartServiceCtrlDispatcher(), I get an error 1063 and it says Access is Denied. I am administrator, how exactly do I get passed this? I'm new to services. Thanks. Code:

// For WinXp, don't forget to link to
// Advapi32.lib library if needed...

#define _WIN32_WINNT 0x0501

#include <windows.h>

#include <stdio.h>
#include <tchar.h>

// Prototypes, just empty skeletons...

void SvcDebugOut(LPSTR String, DWORD Status);
void  WINAPI MyServiceCtrlHandler(DWORD opcode);
void  MyServiceStart(DWORD argc, LPTSTR *argv);
DWORD MyServiceInitialization(DWORD argc, LPTSTR *argv, DWORD *specificError);

void main() 
{

       // Using 2-D array as a table...

       // The name of a service to be run in this service process - "MyService",

       // The function as the starting point for a service - MyServiceStart or

       // a pointer to a ServiceMain() function...

       // The members of the last entry in the table must have NULL values

       // to designate the end of the table...

       SERVICE_TABLE_ENTRY  DispatchTable[] = {{_TEXT("MyService"), (LPSERVICE_MAIN_FUNCTION)MyServiceStart}, {NULL, NULL}};
   if (!StartServiceCtrlDispatcher(DispatchTable))
       SvcDebugOut("StartServiceCtrlDispatcher() failed, error: %d\n", GetLastError());
   else
       printf("StartServiceCtrlDispatcher() looks OK.\n");
   return;
} 

// ==========================================================================
// Prototype definitions...just skeletons here...
void  WINAPI MyServiceCtrlHandler(DWORD opcode)
{
       // Service control information here...
       return;
}

void  MyServiceStart(DWORD argc, LPTSTR *argv)
{
       // Starting service information here...
       return;
}



DWORD MyServiceInitialization(DWORD argc, LPTSTR *argv, DWORD *specificError)
{
       // Service initialization information here...
       return 0;
}

// Very simple info to the standard output...
void SvcDebugOut(LPSTR String, DWORD Status)
{
   CHAR  Buffer[1024];
   printf("In SvcDebugOut() lol!\n");
   if (strlen(String) < 1000)
   {
      sprintf(Buffer, String, Status);
      OutputDebugStringA(Buffer);
   }
   else 
      printf("String too long...\n");
   return;
}

This post answers correctly. As long as you do not start the service "as a service" it will not work.

You need to register it. To do so, look at this file , it is the Apple bonjour service implementation, which is open source.

It gives a good idea of what must be done to install a service. Especially the method InstallService - and RemoveService (if you want to remove it).

Services run under the account that is specified in the properties of their registration. It might not be the same to account that registers the service or starts it. Reads about this.

Many services run under "Network service" account that has very limited capabilities. This makes sense because many services process requests that come from the network. This is why "Network service" was selected by Microsoft as default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM