delphi 控制服务程序代码,让服务启动失败后总是恢复!求助~
BOOL WINAPI LetServiceAlwaysReboot(LPCTSTR ServiceName){SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
if (hSCManager != NULL){
SC_HANDLE hService = OpenService(hSCManager, ServiceName, SC_MANAGER_ALL_ACCESS);//值得一提的是需要用SC_MANAGER_ALL_ACCESS
if (hService != NULL){
SERVICE_FAILURE_ACTIONS failact = { 0 };
SC_ACTION act[3];
act[0].Delay = act[1].Delay = act[2].Delay = 0;
act[0].Type = act[1].Type = act[2].Type = SC_ACTION_RESTART;
failact.cActions = 3;
failact.lpsaActions = act;
failact.dwResetPeriod = 0;
if (ChangeServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, &failact))
{ CloseServiceHandle(hService);
CloseServiceHandle(hSCManager);
return TRUE;
}
CloseServiceHandle(hService);
CloseServiceHandle(hSCManager);
return FALSE;
}
CloseServiceHandle(hSCManager);
return FALSE;
}
else return FALSE;
}
这段代码 有没有高手 可以转成DELPHI XE 可用的啊?。。小弟初来乍到。。。 就是修改指定的服务程序的属性让它出错可以再重启。