static int svc_install_event_source(const char *path) { HKEY hKey; DWORD dwTypes = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE; wchar_t execName[MAX_PATH]; wchar_t regkey[256], *wevent_source; svc_get_fullpath(path, execName, MAX_PATH); wevent_source = zbx_utf8_to_unicode(ZABBIX_EVENT_SOURCE); StringCchPrintf(regkey, ARRSIZE(regkey), EVENTLOG_REG_PATH TEXT("System\\%s"), wevent_source); zbx_free(wevent_source); if (ERROR_SUCCESS != RegCreateKeyEx(HKEY_LOCAL_MACHINE, regkey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, NULL)) { zbx_error("unable to create registry key: %s", strerror_from_system(GetLastError())); return FAIL; } RegSetValueEx(hKey, TEXT("TypesSupported"), 0, REG_DWORD, (BYTE *)&dwTypes, sizeof(DWORD)); RegSetValueEx(hKey, TEXT("EventMessageFile"), 0, REG_EXPAND_SZ, (BYTE *)execName, (DWORD)(wcslen(execName) + 1) * sizeof(wchar_t)); RegCloseKey(hKey); zbx_error("event source [%s] installed successfully", ZABBIX_EVENT_SOURCE); return SUCCEED; }
static void svc_get_command_line(const char *path, int multiple_agents, wchar_t *cmdLine, size_t max_cmdLine) { wchar_t path1[MAX_PATH], path2[MAX_PATH]; svc_get_fullpath(path, path2, MAX_PATH); if (NULL == wcsstr(path2, TEXT(".exe"))) StringCchPrintf(path1, MAX_PATH, TEXT("%s.exe"), path2); else StringCchPrintf(path1, MAX_PATH, path2); if (NULL != CONFIG_FILE) { svc_get_fullpath(CONFIG_FILE, path2, MAX_PATH); StringCchPrintf(cmdLine, max_cmdLine, TEXT("\"%s\" %s--config \"%s\""), path1, (0 == multiple_agents) ? TEXT("") : TEXT("--multiple-agents "), path2); } else StringCchPrintf(cmdLine, max_cmdLine, TEXT("\"%s\""), path1); }
static void svc_get_command_line(const char *path, int multiple_agents, LPTSTR cmdLine, size_t max_cmdLine) { TCHAR path1[MAX_PATH], path2[MAX_PATH]; svc_get_fullpath(path, path2, MAX_PATH); if (NULL == zbx_strstr(path2, TEXT(".exe"))) zbx_wsnprintf(path1, MAX_PATH, TEXT("%s.exe"), path2); else zbx_wsnprintf(path1, MAX_PATH, path2); if (NULL != CONFIG_FILE) { svc_get_fullpath(CONFIG_FILE, path2, MAX_PATH); zbx_wsnprintf(cmdLine, max_cmdLine, TEXT("\"%s\" %s--config \"%s\""), path1, (0 == multiple_agents) ? TEXT("") : TEXT("--multiple-agents "), path2); } else zbx_wsnprintf(cmdLine, max_cmdLine, TEXT("\"%s\""), path1); }