whypurplishblue / cassia

Automatically exported from code.google.com/p/cassia
0 stars 0 forks source link

Add a property to ITerminalServicesSession to fetch the session's virtual IP address #70

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Like this:

// VirtualIP.cpp : Defines the entry point for the console application.

#pragma comment(lib,"Wtsapi32.lib") // Library for WTS functions

#include "stdafx.h"
#include "windows.h"
#include "Wtsapi32.h"

int _tmain(int argc, _TCHAR* argv[])
{

       PWTS_SESSION_ADDRESS wAddr = NULL;
       DWORD dwBytes = 0;            

       // Use WTS_CURRENT_SERVER_HANDLE and
       // WTS_CURRENT_SESSION to get just our virtual address

       if(WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE,
              WTS_CURRENT_SESSION, WTSSessionAddressV4,
              (LPWSTR*)&wAddr, &dwBytes))
       {

              //wAddr->AddressFamily is always 2 (AF_INET)
              printf("Family: %d\n",wAddr->AddressFamily);
              printf("Address: %d.%d.%d.%d\n",wAddr->Address[2],
              wAddr->Address[3],wAddr->Address[4],wAddr->Address[5]);
       } else
       {
             printf("WTSQuerySessionInformation failed. GLE=%d\n",GetLastError());
       }    
       return 0;

}

Original issue reported on code.google.com by danports on 18 Jul 2013 at 11:48

GoogleCodeExporter commented 9 years ago

Original comment by danports on 19 Jul 2013 at 1:56