0

I am using a free application virtualization app - Winflector.

When I use GetSystemMetrics(SM_REMOTESESSION) the function correctly detects that application is running in a remote session, however, WTSQuerySessionInformationA() fails to detect and thus cannot get WTSClientInfo. I want to know, what is difference in the functionalities of these APIs. Also, I am interested in knowing how can I programmatically detect client Side information when running through these kind of applications.

if (GetSystemMetrics(SM_REMOTESESSION))  //passes
        printf("\n\n\tSM_REMOTESESSION says this application is running in a remote session \n");

if (WTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSIsRemoteSession, &pData, &bytesReturned)){   //fails
}

Also wanted to know if there is a possibility that these kind of applications may employ virtual channels (or dynamic virtual channels) infrastructure of windows?

ultimate cause
  • 2,264
  • 4
  • 27
  • 44
  • From [WTSQuerySessionInformationA](https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtsquerysessioninformationa): *"If the function fails, the return value is zero. To get extended error information, call [GetLastError](https://learn.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror)."* Unless you want to compile your code to run on Win9x, call the Unicode version of the API. – IInspectable May 19 '20 at 11:22
  • @IInspectable I tried to look into the error code and it was 2250 that means "no connection". That becomes my question, why the same is not a problem for GetSystemMetrics(). Thanks – ultimate cause May 19 '20 at 13:12
  • @ultimatecause See [WTSIsRemoteSession always returns TRUE](https://stackoverflow.com/questions/56990844/) for how to use `WTSIsRemoteSession`. – Remy Lebeau May 19 '20 at 16:39
  • @RemyLebeau Thanks for second help on same day. In the link you pasted, you emphasized on return value of the function rather than OUT parameter (plz correct me). So, do you mean to say that I should still be referring to OUT parameter, despite getting a failure as return value. I am getting different value only in the case of this application (Winflector). In the RDP sessions I get correct results. Little emphasis please. – ultimate cause May 19 '20 at 18:33
  • @ultimatecause if you read [the answer](https://stackoverflow.com/a/56992573/65863) I had posted, I actually cover BOTH possibilities. You will have to test both ways to see which way is actually implemented by Windows. I didn't test it myself. "*I am getting different value only in the case of this application (Winflector). In the RDP sessions I get correct results*" - what do you mean? I don't understand what you are saying now. – Remy Lebeau May 19 '20 at 18:44
  • @RemyLebeau When I create a session through RDP client, WTSIsRemoteSession, recognizes it, and I dont have any problem. However, when I am using this newer application to access my test application remotely, the WTSIsRemoteSession, fails to recognize that this test application is being remotely accessed. However, if I use, GetSystemMetrics(), it again correctly catches Winflector as well. So, I want to understand what is the difference between two APIs. – ultimate cause May 19 '20 at 18:51
  • @ultimatecause "*when I am using this newer application to access my test application remotely*" - this is where you are losing me. – Remy Lebeau May 19 '20 at 18:59
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/214201/discussion-between-ultimate-cause-and-remy-lebeau). – ultimate cause May 19 '20 at 19:00
  • @ultimatecause `WTSQuerySessionInformationA(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSIsRemoteSession, &pData, &bytesReturned)` works for me on Windows 10 1903. What's your Windows version? – Rita Han May 20 '20 at 06:32
  • @RitaHan-MSFT It does work with Windows 10, but not when the application is being run in Winflector environment. Did you try with Winflector as well? – ultimate cause May 20 '20 at 06:38
  • @ultimatecause Thanks for your confirmation. I didn't try with Winflector. You may need to contact Winflector supplier for this issue. – Rita Han May 20 '20 at 06:43
  • @RitaHan-MSFT They would obviously would not want anyone be able to identify it, because one may use it for several validations. – ultimate cause May 20 '20 at 07:02

0 Answers0