diff --git a/src/win32/registry.c b/src/win32/registry.c index f76866fca33b6c1bb783c0e0adea780474eb235c..bb8b5f9bdd5ef496208197542cad98069a16b613 100644 --- a/src/win32/registry.c +++ b/src/win32/registry.c @@ -27,6 +27,21 @@ char* regGetUsrPath() { return path; } +wchar_t* regWGetUsrPath() { + static wchar_t path[MAX_PATH] = {}; + if (wcslen(path) > 3) { return path; } + HKEY hKey; + const char keyPath[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; + LSTATUS err = RegOpenKeyExA(HKEY_CURRENT_USER, + keyPath, + 0, KEY_READ, &hKey ); + if (err != ERROR_SUCCESS) { return NULL; } + DWORD len = MAX_PATH; + err = RegGetValueW(hKey, NULL, L"Personal", RRF_RT_REG_SZ, NULL, (void*)path, &len); + RegCloseKey(hKey); + return path; +} + wchar_t* getTapGUID() { static wchar_t guid[MAX_PATH] = {}; if (wcslen(guid) > 2) { return guid; } diff --git a/src/win32/registry.h b/src/win32/registry.h index 5dea305ef86971cb2656bbed0c87c40e5df051a2..9299ca13d7c7cc6c007d29291f2c794b5aad025f 100644 --- a/src/win32/registry.h +++ b/src/win32/registry.h @@ -14,7 +14,8 @@ wchar_t* getTapGUID(); wchar_t* getTapName(); wchar_t* getUserSID(LPCWSTR homePath); -char* regGetUsrPath(); +wchar_t* regWGetUsrPath(); +char* regGetUsrPath(); #ifdef __cplusplus }