安装服务和卸载服务只是分别将服务进程写入SCM或删除可并没有向SCM指明服务程序的入口点而指明入口点的函数StartServiceCtrlDispatcher()都是在main函数中疑问:根据这个启动模式,SCM->ServiceMain当电脑启动时,没有指明ServiceMain的指针,SCM如何控制服务程序的启动?

解决方案 »

  1.   

    http://dev.csdn.net/article/29/29425.shtm
      

  2.   

    http://dev.csdn.net/article/29/29425.shtm
    没SCM指针时不能直接控制.可能用WINDOWS服务控制台
      

  3.   

    A function that provides the entry point for the actual service code. In the examples this function is called ServiceMain, but you can call it anything you like. You pass the address of this function to the service manager when the service is first started. 按照MSDN的说法,需要在服务第一次启动的时候传递该函数的地址给服务管理器可是为什么都不把StartServiceCtrlDispatcher()写在install函数中而是分开写在main中这样是不是安装完服务后只要不从控制台进行第一次启动,服务都不会自动启动?
      

  4.   

    在我们通过控制面板或NET START命令启动一个service时, Service Control Manager (SCM)从注册表里拿到service的可执行程序名,然后运行这个程序,从程序的入口main方法里得到service的service_main方法,然后就进入service_main运行。-----------------------------------------
    按照上面CSDN文章的说法,通过手动启动服务的时候SCM->执行程序->main->StartServiceCtrlDispatcher->ServiceMain就是说服务每次运行,无论是在机器启动还是手动启动,都必须执行StartServiceCtrlDispatcher()?You pass the address of this function to the service manager when the service is first started.这句话中的first started是指服务安装后的第一次,还是每次机器启动的第一次?