Question

I'm trying to test the different system paths that is supposed to be returned by GetWindowsDirectory and GetSystemWindowsDirectory APIs on a console and via a remote connection. According to the documentation:

With Terminal Services, the GetSystemWindowsDirectory function retrieves the path of the system Windows directory, while the GetWindowsDirectory function retrieves the path of a Windows directory that is private for each user. On a single-user system, GetSystemWindowsDirectory is the same as GetWindowsDirectory.

I can't seem to see any difference. They both return "C:\Windows" in either.

Can someone explain why am I not seeing what the documentation announced for the terminal services?

EDIT: Here's a little C++ code sample I was running:

//Check if RDP session
BOOL bRDP = FALSE;
DWORD dwSessID = -1;
::ProcessIdToSessionId(::GetCurrentProcessId(), &dwSessID);
DWORD dwSz;
LPTSTR ppBuffer = NULL;
if(WTSQuerySessionInformation(NULL, dwSessID, WTSClientProtocolType, &ppBuffer, &dwSz))
{
    bRDP = *(USHORT*)ppBuffer == 2;
    WTSFreeMemory(ppBuffer);
}

_tprintf(_T("%s\n"), !bRDP ? _T("Console Session") : _T("RDP Session"));

//Get system folder
TCHAR buff[MAX_PATH * 2];

buff[0] = 0;
GetSystemWindowsDirectory(buff, SIZEOF(buff));
_tprintf(_T("Sysfolder1: %s\n"), buff);

buff[0] = 0;
GetWindowsDirectory(buff, SIZEOF(buff));
_tprintf(_T("Sysfolder2: %s\n"), buff);

And here's the output I'm getting from a remote desktop session:

RDP Session
Sysfolder1: C:\WINDOWS
Sysfolder2: C:\WINDOWS
Was it helpful?

Solution

Thanks to @RaymondChen and @Stefan, only if one specifies the /TSAWARE:NO linker option in the application settings, you will see the difference in the output: enter image description here

In this case I got this output:

RDP Session
Sysfolder1: C:\WINDOWS
Sysfolder2: C:\Documents and Settings\RemoteUserA\WINDOWS
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top