BOOLEAN ConCfgOpenUserSettings(LPCWSTR ConsoleTitle, PHKEY hSubKey, REGSAM samDesired, BOOLEAN Create) { BOOLEAN RetVal = TRUE; NTSTATUS Status; WCHAR szBuffer[MAX_PATH] = L"Console\\"; WCHAR szBuffer2[MAX_PATH] = L""; HKEY hKey; // CurrentUserKeyHandle /* * Console properties are stored under the HKCU\Console\* key. * * We use the original console title as the subkey name for storing * console properties. We need to distinguish whether we were launched * via the console application directly or via a shortcut. * * If the title of the console corresponds to a path (more precisely, * if the title is of the form: C:\ReactOS\<some_path>\<some_app.exe>), * then use the corresponding unexpanded path and with the backslashes * replaced by underscores, to make the registry happy, * i.e. %SystemRoot%_<some_path>_<some_app.exe> */ /* Open the per-user registry key where the console properties are saved */ Status = RtlOpenCurrentUser(/*samDesired*/MAXIMUM_ALLOWED, (PHANDLE)&/*CurrentUserKeyHandle*/hKey); if (!NT_SUCCESS(Status)) { DPRINT1("RtlOpenCurrentUser failed, Status = 0x%08lx\n", Status); SetLastError(RtlNtStatusToDosError(Status)); return FALSE; } /* * Try to open properties via the console title: * to make the registry happy, replace all the * backslashes by underscores. */ TranslateConsoleName(szBuffer2, ConsoleTitle, MAX_PATH); /* Create the registry path */ wcsncat(szBuffer, szBuffer2, MAX_PATH - wcslen(szBuffer) - 1); /* Create or open the registry key */ if (Create) { /* Create the key */ RetVal = (RegCreateKeyExW(hKey, szBuffer, 0, NULL, REG_OPTION_NON_VOLATILE, samDesired, NULL, hSubKey, NULL) == ERROR_SUCCESS); } else { /* Open the key */ RetVal = (RegOpenKeyExW(hKey, szBuffer, 0, samDesired, hSubKey) == ERROR_SUCCESS); } /* Close the parent key and return success or not */ NtClose(hKey); return RetVal; }
/*static*/ BOOL ConSrvOpenUserSettings(DWORD ProcessId, LPCWSTR ConsoleTitle, PHKEY hSubKey, REGSAM samDesired, BOOL bCreate) { BOOL bRet = TRUE; WCHAR szBuffer[MAX_PATH] = L"Console\\"; WCHAR szBuffer2[MAX_PATH] = L""; HKEY hKey; /* * Console properties are stored under the HKCU\Console\* key. * * We use the original console title as the subkey name for storing * console properties. We need to distinguish whether we were launched * via the console application directly or via a shortcut. * * If the title of the console corresponds to a path (more precisely, * if the title is of the form: C:\ReactOS\<some_path>\<some_app.exe>), * then use the corresponding unexpanded path and with the backslashes * replaced by underscores, to make the registry happy, * i.e. %SystemRoot%_<some_path>_<some_app.exe> */ /* Open the registry key where we saved the console properties */ if (!OpenUserRegistryPathPerProcessId(ProcessId, &hKey, samDesired)) { DPRINT1("OpenUserRegistryPathPerProcessId failed\n"); return FALSE; } /* * Try to open properties via the console title: * to make the registry happy, replace all the * backslashes by underscores. */ TranslateConsoleName(szBuffer2, ConsoleTitle, MAX_PATH); /* Create the registry path */ wcsncat(szBuffer, szBuffer2, MAX_PATH); /* Create or open the registry key */ if (bCreate) { /* Create the key */ bRet = (RegCreateKeyExW(hKey, szBuffer, 0, NULL, REG_OPTION_NON_VOLATILE, samDesired, NULL, hSubKey, NULL) == ERROR_SUCCESS); } else { /* Open the key */ bRet = (RegOpenKeyExW(hKey, szBuffer, 0, samDesired, hSubKey) == ERROR_SUCCESS); } /* Close the parent key and return success or not */ RegCloseKey(hKey); return bRet; }