1

Consider we have this function:

#include <iostream>
#include <string>
#include <Windows.h>
#include <Winerror.h>
#include <Shlobj.h>

std::wstring get_common_appdata()
{
    wchar_t buf[MAX_PATH + 1] = { 0 };
    std::wstring path;
    if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_DEFAULT, buf)))
    {
        path = buf;
    }
    return path;
}

int main(int, char**)
{
    std::wcout << get_common_appdata() << std::endl;
}

which typically while local debugging outputs:

C:\ProgramData

(on Windows 7/8.1/10).

But when remote debugging on remote (virtual) test machine (using Visual Studio 2013 Remote Debugger) it outputs:

%SystemDrive%\ProgramData

And when I run this simple program on virtual machine itself, it again returns correct

C:\ProgramData

Is it bug in WinAPI or it is already documented anywhere? How to deal with this behavior?

vladon
  • 8,158
  • 2
  • 47
  • 91
  • Hmm, that's not exactly a common complaint. Fire-up Regedit.exe on that machine and have a look-see at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders – Hans Passant Sep 06 '15 at 16:48
  • Try with -1 value of `hToken` parameter. "Assigning the hToken parameter a value of -1 indicates the Default User." – c-smile Sep 06 '15 at 16:50
  • @HansPassant It contains correct path: `C:\ProgramData`, http://i.imgur.com/Fj2Wk4C.png - it's a fresh installed Windows 8.1 downloaded from Microsoft web-site (trial version) – vladon Sep 06 '15 at 16:50
  • @c-smile Just tried, it is not helped, `SHGetFolderPathW` still returns `%SystemDrive%\ProgramData` :-( – vladon Sep 06 '15 at 16:57
  • It almost looks like the environment variables aren't getting mapped, or that the remote debugging connection is preventing expansion. Of course this is just speculation. If you print the value of the `%systemdrive%` environment variable is it correct when debugging remotely? – theB Sep 07 '15 at 03:12

0 Answers0