Skip to content

Commit

Permalink
Change registry key used for the Monitor settings
Browse files Browse the repository at this point in the history
  • Loading branch information
redddcyclone committed Jan 22, 2024
1 parent 6765363 commit 82930a0
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions GLPI-AgentMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,11 +705,11 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance


// Load GLPI Agent Monitor settings from registry
wsprintf(szKey, L"SOFTWARE\\%s\\Installer", SERVICE_NAME);
wsprintf(szKey, L"SOFTWARE\\%s\\Monitor", SERVICE_NAME);
LONG lRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ | KEY_WOW64_64KEY, &hk);
if (lRes != ERROR_SUCCESS)
{
wsprintf(szKey, L"SOFTWARE\\WOW6432Node\\%s\\Installer", SERVICE_NAME);
wsprintf(szKey, L"SOFTWARE\\WOW6432Node\\%s\\Monitor", SERVICE_NAME);
lRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ | KEY_WOW64_64KEY, &hk);
}

Expand All @@ -719,7 +719,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance

// Get new ticket URL
DWORD szNewTicketURLLen = sizeof(szNewTicketURL);
lRes = RegQueryValueEx(hk, L"AgentMonitor-NewTicket-URL", 0, NULL, (LPBYTE)szNewTicketURL, &szNewTicketURLLen);
lRes = RegQueryValueEx(hk, L"NewTicket-URL", 0, NULL, (LPBYTE)szNewTicketURL, &szNewTicketURLLen);
if (lRes != ERROR_SUCCESS) {
// Default value if not found
wsprintf(szNewTicketURL, L"%s/front/ticket.form.php", szServer);
Expand Down Expand Up @@ -886,7 +886,7 @@ LRESULT CALLBACK SettingsDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
return TRUE;
case IDC_BTN_SAVE:
{
HKEY hk;
HKEY hk, hkMonitor;
LONG lRes;
WCHAR szKey[MAX_PATH];

Expand All @@ -897,13 +897,13 @@ LRESULT CALLBACK SettingsDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
szTempNewTicketURL[copiedChars] = '\0';

// Save settings in registry
wsprintf(szKey, L"SOFTWARE\\%s\\Installer", SERVICE_NAME);
wsprintf(szKey, L"SOFTWARE\\%s", SERVICE_NAME);
lRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_WRITE | KEY_WOW64_64KEY, &hk);
if (lRes != ERROR_SUCCESS)
{
if (lRes == ERROR_FILE_NOT_FOUND)
{
wsprintf(szKey, L"SOFTWARE\\WOW6432Node\\%s\\Installer", SERVICE_NAME);
wsprintf(szKey, L"SOFTWARE\\WOW6432Node\\%s", SERVICE_NAME);
lRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_WRITE | KEY_WOW64_64KEY, &hk);
if (lRes != ERROR_SUCCESS)
{
Expand All @@ -916,16 +916,30 @@ LRESULT CALLBACK SettingsDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
return FALSE;
}
}
// Save new ticket URL
size_t szTempNewTicketURLLen = wcslen(szTempNewTicketURL) * sizeof(WCHAR);
lRes = RegSetValueEx(hk, L"AgentMonitor-NewTicket-URL", 0, REG_SZ,
(LPBYTE)szTempNewTicketURL, (DWORD)szTempNewTicketURLLen);
wsprintf(szKey, L"%s\\Monitor", szKey);
lRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_WRITE | KEY_WOW64_64KEY, &hkMonitor);
if (lRes != ERROR_SUCCESS)
{
LoadStringAndMessageBox(hInst, hWnd, IDS_ERR_SAVE_SETTINGS, IDS_ERROR, MB_OK | MB_ICONERROR, lRes);
return FALSE;
lRes = RegCreateKeyEx(hk, L"Monitor", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkMonitor, NULL);
if (lRes != ERROR_SUCCESS)
{
LoadStringAndMessageBox(hInst, hWnd, IDS_ERR_SAVE_SETTINGS, IDS_ERROR, MB_OK | MB_ICONERROR, lRes);
return FALSE;
}
}
// Save new ticket URL if it was changed
if (wcscmp(szTempNewTicketURL, szNewTicketURL) != 0) {
size_t szTempNewTicketURLLen = wcslen(szTempNewTicketURL) * sizeof(WCHAR);
lRes = RegSetValueEx(hkMonitor, L"NewTicket-URL", 0, REG_SZ,
(LPBYTE)szTempNewTicketURL, (DWORD)szTempNewTicketURLLen);
if (lRes != ERROR_SUCCESS)
{
LoadStringAndMessageBox(hInst, hWnd, IDS_ERR_SAVE_SETTINGS, IDS_ERROR, MB_OK | MB_ICONERROR, lRes);
return FALSE;
}
}

RegCloseKey(hkMonitor);
RegCloseKey(hk);

// Store new ticket URL in memory
Expand Down

0 comments on commit 82930a0

Please sign in to comment.