I know I can use GetSystemDirectory()
to get the directory of C:\Windows\System32
, but I'm wondering if there's a way to get this directory path below regardless of how the OS is localized or whether I'm running as a normal user or the SYSTEM account:
C:\Windows\System32\config\systemprofile\AppData\Local\TEMP
Or at least as far as C:\Windows\System32\config\systemprofile\AppData
I tried using the SHGFP_TYPE_DEFAULT
instead of SHGFP_TYPE_CURRENT
option for SHGetFolderPath()
but this will return the currently running user's directory instead of SYSTEM's when not running as SYSTEM.
void GetUserLocalTempPath(std::wstring& input_parameter) {
HWND folder_handle = { 0 };
WCHAR temp_path[MAX_PATH];
auto get_folder = SHGetFolderPath(
folder_handle, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_DEFAULT, temp_path
);
if (get_folder == S_OK) {
input_parameter = static_cast<const wchar_t*>(temp_path);
input_parameter.append(L"\\TEMP");
CloseHandle(folder_handle);
}
}