From: Alistair Leslie-Hughes leslie_alistair@hotmail.com
If a DSN is System wide, we need to write to the HKEY_LOCAL_MACHINE part of the registry not HKEY_CURRENT_USER which it's currently doing. --- dlls/odbccp32/odbccp32.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/dlls/odbccp32/odbccp32.c b/dlls/odbccp32/odbccp32.c index f1e6cb810c4..df940951f22 100644 --- a/dlls/odbccp32/odbccp32.c +++ b/dlls/odbccp32/odbccp32.c @@ -1807,6 +1807,7 @@ BOOL WINAPI SQLWritePrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry static const WCHAR empty[] = {0}; LONG ret; HKEY hkey; + WCHAR regpath[256];
clear_errors(); TRACE("%s %s %s %s\n", debugstr_w(lpszSection), debugstr_w(lpszEntry), @@ -1818,7 +1819,26 @@ BOOL WINAPI SQLWritePrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry return FALSE; }
- if ((ret = RegCreateKeyW(HKEY_CURRENT_USER, odbcW, &hkey)) == ERROR_SUCCESS) + wcscpy(regpath, L"Software\ODBC\"); + wcscat(regpath, lpszFilename); + wcscat(regpath, L"\"); + wcscat(regpath, lpszSection); + + /* Check an existing key first before writing a new one */ + if ((ret = RegOpenKeyW(HKEY_CURRENT_USER, regpath, &hkey)) != ERROR_SUCCESS) + { + ret = RegOpenKeyW(HKEY_LOCAL_MACHINE, regpath, &hkey); + } + + if (ret == ERROR_SUCCESS) + { + if(lpszString) + ret = RegSetValueExW(hkey, lpszEntry, 0, REG_SZ, (BYTE*)lpszString, (lstrlenW(lpszString)+1)*sizeof(WCHAR)); + else + ret = RegSetValueExW(hkey, lpszEntry, 0, REG_SZ, (BYTE*)empty, sizeof(empty)); + RegCloseKey(hkey); + } + else if ((ret = RegCreateKeyW(HKEY_CURRENT_USER, odbcW, &hkey)) == ERROR_SUCCESS) { HKEY hkeyfilename;