Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;Windows服务错误1063_C++_Service_Startup - Fatal编程技术网

C++ C++;Windows服务错误1063

C++ C++;Windows服务错误1063,c++,service,startup,C++,Service,Startup,我正在尝试开发我的第一个windows服务,我正在windows 7 MS VC++10.0中调试。一旦它调用startServiceCtrlDiscoveryPatcher(),我就会收到一个错误1063,它说访问被拒绝。我是管理员,我怎样才能通过这个考试?我不熟悉服务业。谢谢代码: // For WinXp, don't forget to link to // Advapi32.lib library if needed... #define _WIN32_WINNT 0x0501 #

我正在尝试开发我的第一个windows服务,我正在windows 7 MS VC++10.0中调试。一旦它调用startServiceCtrlDiscoveryPatcher(),我就会收到一个错误1063,它说访问被拒绝。我是管理员,我怎样才能通过这个考试?我不熟悉服务业。谢谢代码:

// 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;
}
//对于WinXp,不要忘记链接到
//Advapi32.lib库(如果需要)。。。
#定义_WIN32_WINNT 0x0501
#包括
#包括
#包括
//原型,只是空骨架。。。
void SvcDebugOut(LPSTR字符串,DWORD状态);
void WINAPI MyServiceCtrlHandler(DWORD操作码);
void MyServiceStart(DWORD argc,LPTSTR*argv);
DWORD MyServiceInitialization(DWORD argc、LPTSTR*argv、DWORD*specificError);
void main()
{
//使用二维数组作为表。。。
//要在此服务进程中运行的服务的名称-“MyService”,
//作为服务起点的函数-MyServiceStart或
//指向ServiceMain()函数的指针。。。
//表中最后一个条目的成员必须具有空值
//要指定表的结尾。。。
SERVICE_TABLE_ENTRY DispatchTable[]={{{{u TEXT(“MyService”),(LPSERVICE_MAIN_函数)MyServiceStart},{NULL,NULL};
如果(!StartServiceCtrlDispatcher(调度表))
SvcDebugOut(“StartServiceCtrlDispatcher()失败,错误:%d\n”,GetLastError());
其他的
printf(“StartServiceCtrlDispatcher()看起来正常。\n”);
返回;
} 
// ==========================================================================
//原型定义…这里只是骨架。。。
void WINAPI MyServiceCtrlHandler(DWORD操作码)
{
//服务控制信息在此。。。
返回;
}
void MyServiceStart(DWORD argc,LPTSTR*argv)
{
//正在此处启动服务信息。。。
返回;
}
DWORD MyServiceInitialization(DWORD argc、LPTSTR*argv、DWORD*specificError)
{
//服务初始化信息在此。。。
返回0;
}
//标准输出的非常简单的信息。。。
void SvcDebugOut(LPSTR字符串,DWORD状态)
{
字符缓冲区[1024];
printf(“In-SvcDebugOut()lol!\n”);
if(strlen(字符串)<1000)
{
sprintf(缓冲区、字符串、状态);
OutputDebugStringA(缓冲区);
}
其他的
printf(“字符串太长…\n”);
返回;
}

服务在其注册属性中指定的帐户下运行。注册或启动服务的帐户可能不同。读到了这篇文章

许多服务在“网络服务”帐户下运行,但功能非常有限。这是有意义的,因为许多服务处理来自网络的请求。这就是Microsoft选择“网络服务”作为默认服务的原因。

这回答正确。只要您不启动“作为服务”的服务,它就不会工作

你需要注册它。要做到这一点,请看这个,这是Apple bonjour服务实现,它是开源的

它很好地说明了安装服务必须做什么。特别是InstallService-and RemoveService方法(如果您想删除它)