else if (1 == argc)
{
if (0 == isAdmin())
{
printf("Start Service - Must be run as an administrator to use this operation\n");
ReportError(TRUE, "Start Service - Must be run as an administrator to use this operation\n");
return -1;
}
printf("%s: StartServiceCtrlDispatcher to run.\n", __FUNCTION__);
ReportError(FALSE, "%s: StartServiceCtrlDispatcher to run.\n", __FUNCTION__);
StartServiceCtrlDispatcher(ServiceTable);
return 0;
}
其中,isAdmin和ReportError是我写的函数,isAdmin()判断是否具有Administrator权限,ReportError()将后边的内容写入到system event log中.
我在Service Management中手动启动这个服务,可以看到event log中有成功字样,而且service也处于了Started状态.
但是,如果我在具有admin权限的cmd中执行这个service .exe,虽然在console和event log都有成功的字样,但是在Service Management中该service并未启动(已按F5刷新了),而且Task Manager里也没有service .exe的进程.
呼唤远方