描述:
我写了一个服务程序CSService.exe,其中涉及ADO调用SQL Server数据库,当CSService.exe随系统启动时,日值报错不能连接数据库. 由此我猜想一定是在CSService.exe服务启动之前,COM(由于用到了ADO)RpcSs的相关服务和SQL Server的相关服务MSSQLSERVER可能没有起来导致的.所以我这个CSService.exe应该是依赖这两个服务的吧.看MSDN关于CreateService依赖性的相关说明
lpDependencies
[in] Pointer to a double null-terminated array of null-separated names of services or load ordering groups that the system must start before this service. Specify NULL or an empty string if the service has no dependencies. Dependency on a group means that this service can run if at least one member of the group is running after an attempt to start all members of the group.
You must prefix group names with SC_GROUP_IDENTIFIER so that they can be distinguished from a service name, because services and service groups share the same name space.
但是不知道怎么设置这个lpDependencies才是正确的方法,我是这样设置的
SC_HANDLE hService = ::CreateService(
.........
_T("RpcSc\0MSSQLSERVER\0SC_GROUP_IDENTIFIERSvrGroup\0\0"),
NULL,
NULL);
注册服务成功,但书运行报错:
MService 服务和下列不存在的服务存在相依的关系: SC_GROUP_IDENTIFIERSvrGroup
请教正解?
另外: 请问我这样设置成功的话,是不是系统就会自动保证服务的先后顺序?
解决方案1:
搞定了?
接分
提示已经很明显了.
SC_HANDLE hService = ::CreateService(
.........
_T("RpcSc\0MSSQLSERVER\0\0"),
NULL,
NULL);
这样就应该可以了吧.
不会,呵呵