In w32api, the definition of WTS_CURRENT_SESSION in wtsapi32.h is

#define WTS_CURRENT_SESSION       0

However, from the Microsoft Windows SDK for Windows Server 2008 and .NET
Framework 3.5
(http://www.microsoft.com/downloads/details.aspx?FamilyId=E6E1C3DF-A74F-
4207-8586-711EBE331CDC&displaylang=en), the definition is 

/*
 *  Specifies the current session (SessionId)
 */
#define WTS_CURRENT_SESSION ((DWORD)-1)


This results in the wrong session being referenced when used in WTS API
calls such as WTSQuerySessionInformation. The following small example
demonstrates the problem: when I run this over an RDP connection to my
Windows box (logged in as an admin user), it prints
  Is a remote connection: 0
which is obviously incorrect. If the "WTS_CURRENT_SESSION" is changed to
"-1", then the expected result
  Is a remote connection: 1
is returned.

/* Compile with gcc -Wall -DWINVER=0x0501 -o test-wts test-wts.c
-lwtsapi32 */

#include <windows.h>
#include <wtsapi32.h>
#include <stdio.h>

int main(void) {
  USHORT *clnProto;
  DWORD size;

  if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE,
WTS_CURRENT_SESSION, WTSClientProtocolType, (LPTSTR *)&clnProto, &size))
{
    printf("Is a remote connection: %d\n", (*clnProto != 0));
    WTSFreeMemory(clnProto);
  }
  return 0;
}

Linton



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply via email to