Home | History | Annotate | Download | only in include
      1 /**
      2  * This file has no copyright assigned and is placed in the Public Domain.
      3  * This file is part of the mingw-w64 runtime package.
      4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
      5  */
      6 #ifndef _INC_WTSAPI
      7 #define _INC_WTSAPI
      8 
      9 #include <_mingw_unicode.h>
     10 
     11 #ifdef __cplusplus
     12 extern "C" {
     13 #endif
     14 
     15 #define WTS_CURRENT_SERVER ((HANDLE)NULL)
     16 #define WTS_CURRENT_SERVER_HANDLE ((HANDLE)NULL)
     17 #define WTS_CURRENT_SERVER_NAME (NULL)
     18 
     19 #define WTS_CURRENT_SESSION ((DWORD)-1)
     20 
     21 #ifndef IDTIMEOUT
     22 #define IDTIMEOUT 32000
     23 #endif
     24 #ifndef IDASYNC
     25 #define IDASYNC 32001
     26 #endif
     27 
     28 #define WTS_WSD_LOGOFF 0x1
     29 #define WTS_WSD_SHUTDOWN 0x2
     30 #define WTS_WSD_REBOOT 0x4
     31 #define WTS_WSD_POWEROFF 0x8
     32 
     33 #define WTS_WSD_FASTREBOOT 0x10
     34 
     35   typedef enum _WTS_CONNECTSTATE_CLASS {
     36     WTSActive,WTSConnected,WTSConnectQuery,WTSShadow,WTSDisconnected,WTSIdle,WTSListen,WTSReset,WTSDown,WTSInit
     37   } WTS_CONNECTSTATE_CLASS;
     38 
     39   typedef struct _WTS_SERVER_INFOW {
     40     LPWSTR pServerName;
     41   } WTS_SERVER_INFOW,*PWTS_SERVER_INFOW;
     42 
     43   typedef struct _WTS_SERVER_INFOA {
     44     LPSTR pServerName;
     45   } WTS_SERVER_INFOA,*PWTS_SERVER_INFOA;
     46 
     47 #define WTS_SERVER_INFO __MINGW_NAME_AW(WTS_SERVER_INFO)
     48 #define PWTS_SERVER_INFO __MINGW_NAME_AW(PWTS_SERVER_INFO)
     49 
     50   typedef struct _WTS_SESSION_INFOW {
     51     DWORD SessionId;
     52     LPWSTR pWinStationName;
     53     WTS_CONNECTSTATE_CLASS State;
     54   } WTS_SESSION_INFOW,*PWTS_SESSION_INFOW;
     55 
     56   typedef struct _WTS_SESSION_INFOA {
     57     DWORD SessionId;
     58     LPSTR pWinStationName;
     59     WTS_CONNECTSTATE_CLASS State;
     60   } WTS_SESSION_INFOA,*PWTS_SESSION_INFOA;
     61 
     62 #define WTS_SESSION_INFO __MINGW_NAME_AW(WTS_SESSION_INFO)
     63 #define PWTS_SESSION_INFO __MINGW_NAME_AW(PWTS_SESSION_INFO)
     64 
     65   typedef struct _WTS_PROCESS_INFOW {
     66     DWORD SessionId;
     67     DWORD ProcessId;
     68     LPWSTR pProcessName;
     69     PSID pUserSid;
     70   } WTS_PROCESS_INFOW,*PWTS_PROCESS_INFOW;
     71 
     72   typedef struct _WTS_PROCESS_INFOA {
     73     DWORD SessionId;
     74     DWORD ProcessId;
     75     LPSTR pProcessName;
     76     PSID pUserSid;
     77   } WTS_PROCESS_INFOA,*PWTS_PROCESS_INFOA;
     78 
     79 #define WTS_PROCESS_INFO __MINGW_NAME_AW(WTS_PROCESS_INFO)
     80 #define PWTS_PROCESS_INFO __MINGW_NAME_AW(PWTS_PROCESS_INFO)
     81 
     82 #define WTS_PROTOCOL_TYPE_CONSOLE 0
     83 #define WTS_PROTOCOL_TYPE_ICA 1
     84 #define WTS_PROTOCOL_TYPE_RDP 2
     85 
     86   typedef enum _WTS_INFO_CLASS {
     87     WTSInitialProgram       = 0,
     88     WTSApplicationName      = 1,
     89     WTSWorkingDirectory     = 2,
     90     WTSOEMId                = 3,
     91     WTSSessionId            = 4,
     92     WTSUserName             = 5,
     93     WTSWinStationName       = 6,
     94     WTSDomainName           = 7,
     95     WTSConnectState         = 8,
     96     WTSClientBuildNumber    = 9,
     97     WTSClientName           = 10,
     98     WTSClientDirectory      = 11,
     99     WTSClientProductId      = 12,
    100     WTSClientHardwareId     = 13,
    101     WTSClientAddress        = 14,
    102     WTSClientDisplay        = 15,
    103     WTSClientProtocolType   = 16,
    104     WTSIdleTime             = 17,
    105     WTSLogonTime            = 18,
    106     WTSIncomingBytes        = 19,
    107     WTSOutgoingBytes        = 20,
    108     WTSIncomingFrames       = 21,
    109     WTSOutgoingFrames       = 22,
    110     WTSClientInfo           = 23,
    111     WTSSessionInfo          = 24
    112   } WTS_INFO_CLASS;
    113 
    114   typedef struct _WTS_CLIENT_ADDRESS {
    115     DWORD AddressFamily;
    116     BYTE Address[20];
    117   } WTS_CLIENT_ADDRESS,*PWTS_CLIENT_ADDRESS;
    118 
    119   typedef struct _WTS_CLIENT_DISPLAY {
    120     DWORD HorizontalResolution;
    121     DWORD VerticalResolution;
    122     DWORD ColorDepth;
    123   } WTS_CLIENT_DISPLAY,*PWTS_CLIENT_DISPLAY;
    124 
    125   typedef enum _WTS_CONFIG_CLASS {
    126     WTSUserConfigInitialProgram,WTSUserConfigWorkingDirectory,WTSUserConfigfInheritInitialProgram,WTSUserConfigfAllowLogonTerminalServer,
    127     WTSUserConfigTimeoutSettingsConnections,WTSUserConfigTimeoutSettingsDisconnections,WTSUserConfigTimeoutSettingsIdle,
    128     WTSUserConfigfDeviceClientDrives,WTSUserConfigfDeviceClientPrinters,WTSUserConfigfDeviceClientDefaultPrinter,WTSUserConfigBrokenTimeoutSettings,
    129     WTSUserConfigReconnectSettings,WTSUserConfigModemCallbackSettings,WTSUserConfigModemCallbackPhoneNumber,WTSUserConfigShadowingSettings,
    130     WTSUserConfigTerminalServerProfilePath,WTSUserConfigTerminalServerHomeDir,WTSUserConfigTerminalServerHomeDirDrive,
    131     WTSUserConfigfTerminalServerRemoteHomeDir
    132   } WTS_CONFIG_CLASS;
    133 
    134 #define WTS_EVENT_NONE 0x0
    135 #define WTS_EVENT_CREATE 0x1
    136 #define WTS_EVENT_DELETE 0x2
    137 #define WTS_EVENT_RENAME 0x4
    138 #define WTS_EVENT_CONNECT 0x8
    139 #define WTS_EVENT_DISCONNECT 0x10
    140 #define WTS_EVENT_LOGON 0x20
    141 #define WTS_EVENT_LOGOFF 0x40
    142 #define WTS_EVENT_STATECHANGE 0x80
    143 #define WTS_EVENT_LICENSE 0x100
    144 #define WTS_EVENT_ALL 0x7fffffff
    145 #define WTS_EVENT_FLUSH 0x80000000
    146 
    147   typedef enum _WTS_VIRTUAL_CLASS {
    148     WTSVirtualClientData,WTSVirtualFileHandle
    149   } WTS_VIRTUAL_CLASS;
    150 
    151 #define WTSEnumerateServers __MINGW_NAME_AW(WTSEnumerateServers)
    152 #define WTSOpenServer __MINGW_NAME_AW(WTSOpenServer)
    153 #define WTSEnumerateSessions __MINGW_NAME_AW(WTSEnumerateSessions)
    154 #define WTSEnumerateProcesses __MINGW_NAME_AW(WTSEnumerateProcesses)
    155 #define WTSQuerySessionInformation __MINGW_NAME_AW(WTSQuerySessionInformation)
    156 #define WTSQueryUserConfig __MINGW_NAME_AW(WTSQueryUserConfig)
    157 #define WTSSetUserConfig __MINGW_NAME_AW(WTSSetUserConfig)
    158 #define WTSSendMessage __MINGW_NAME_AW(WTSSendMessage)
    159 
    160   WINBOOL WINAPI WTSEnumerateServersW(LPWSTR pDomainName,DWORD Reserved,DWORD Version,PWTS_SERVER_INFOW *ppServerInfo,DWORD *pCount);
    161   WINBOOL WINAPI WTSEnumerateServersA(LPSTR pDomainName,DWORD Reserved,DWORD Version,PWTS_SERVER_INFOA *ppServerInfo,DWORD *pCount);
    162   HANDLE WINAPI WTSOpenServerW(LPWSTR pServerName);
    163   HANDLE WINAPI WTSOpenServerA(LPSTR pServerName);
    164   VOID WINAPI WTSCloseServer(HANDLE hServer);
    165   WINBOOL WINAPI WTSEnumerateSessionsW(HANDLE hServer,DWORD Reserved,DWORD Version,PWTS_SESSION_INFOW *ppSessionInfo,DWORD *pCount);
    166   WINBOOL WINAPI WTSEnumerateSessionsA(HANDLE hServer,DWORD Reserved,DWORD Version,PWTS_SESSION_INFOA *ppSessionInfo,DWORD *pCount);
    167   WINBOOL WINAPI WTSEnumerateProcessesW(HANDLE hServer,DWORD Reserved,DWORD Version,PWTS_PROCESS_INFOW *ppProcessInfo,DWORD *pCount);
    168   WINBOOL WINAPI WTSEnumerateProcessesA(HANDLE hServer,DWORD Reserved,DWORD Version,PWTS_PROCESS_INFOA *ppProcessInfo,DWORD *pCount);
    169   WINBOOL WINAPI WTSTerminateProcess(HANDLE hServer,DWORD ProcessId,DWORD ExitCode);
    170   WINBOOL WINAPI WTSQuerySessionInformationW(HANDLE hServer,DWORD SessionId,WTS_INFO_CLASS WTSInfoClass,LPWSTR *ppBuffer,DWORD *pBytesReturned);
    171   WINBOOL WINAPI WTSQuerySessionInformationA(HANDLE hServer,DWORD SessionId,WTS_INFO_CLASS WTSInfoClass,LPSTR *ppBuffer,DWORD *pBytesReturned);
    172   WINBOOL WINAPI WTSQueryUserConfigW(LPWSTR pServerName,LPWSTR pUserName,WTS_CONFIG_CLASS WTSConfigClass,LPWSTR *ppBuffer,DWORD *pBytesReturned);
    173   WINBOOL WINAPI WTSQueryUserConfigA(LPSTR pServerName,LPSTR pUserName,WTS_CONFIG_CLASS WTSConfigClass,LPSTR *ppBuffer,DWORD *pBytesReturned);
    174   WINBOOL WINAPI WTSSetUserConfigW(LPWSTR pServerName,LPWSTR pUserName,WTS_CONFIG_CLASS WTSConfigClass,LPWSTR pBuffer,DWORD DataLength);
    175   WINBOOL WINAPI WTSSetUserConfigA(LPSTR pServerName,LPSTR pUserName,WTS_CONFIG_CLASS WTSConfigClass,LPSTR pBuffer,DWORD DataLength);
    176   WINBOOL WINAPI WTSSendMessageW(HANDLE hServer,DWORD SessionId,LPWSTR pTitle,DWORD TitleLength,LPWSTR pMessage,DWORD MessageLength,DWORD Style,DWORD Timeout,DWORD *pResponse,WINBOOL bWait);
    177   WINBOOL WINAPI WTSSendMessageA(HANDLE hServer,DWORD SessionId,LPSTR pTitle,DWORD TitleLength,LPSTR pMessage,DWORD MessageLength,DWORD Style,DWORD Timeout,DWORD *pResponse,WINBOOL bWait);
    178   WINBOOL WINAPI WTSDisconnectSession(HANDLE hServer,DWORD SessionId,WINBOOL bWait);
    179   WINBOOL WINAPI WTSLogoffSession(HANDLE hServer,DWORD SessionId,WINBOOL bWait);
    180   WINBOOL WINAPI WTSShutdownSystem(HANDLE hServer,DWORD ShutdownFlag);
    181   WINBOOL WINAPI WTSWaitSystemEvent(HANDLE hServer,DWORD EventMask,DWORD *pEventFlags);
    182   HANDLE WINAPI WTSVirtualChannelOpen(HANDLE hServer,DWORD SessionId,LPSTR pVirtualName);
    183   WINBOOL WINAPI WTSVirtualChannelClose(HANDLE hChannelHandle);
    184   WINBOOL WINAPI WTSVirtualChannelRead(HANDLE hChannelHandle,ULONG TimeOut,PCHAR Buffer,ULONG BufferSize,PULONG pBytesRead);
    185   WINBOOL WINAPI WTSVirtualChannelWrite(HANDLE hChannelHandle,PCHAR Buffer,ULONG Length,PULONG pBytesWritten);
    186   WINBOOL WINAPI WTSVirtualChannelPurgeInput(HANDLE hChannelHandle);
    187   WINBOOL WINAPI WTSVirtualChannelPurgeOutput(HANDLE hChannelHandle);
    188   WINBOOL WINAPI WTSVirtualChannelQuery(HANDLE hChannelHandle,WTS_VIRTUAL_CLASS,PVOID *ppBuffer,DWORD *pBytesReturned);
    189   VOID WINAPI WTSFreeMemory(PVOID pMemory);
    190 
    191 #define NOTIFY_FOR_ALL_SESSIONS 1
    192 #define NOTIFY_FOR_THIS_SESSION 0
    193 
    194   WINBOOL WINAPI WTSRegisterSessionNotification(HWND hWnd,DWORD dwFlags);
    195   WINBOOL WINAPI WTSUnRegisterSessionNotification(HWND hWnd);
    196   WINBOOL WINAPI WTSQueryUserToken(ULONG SessionId,PHANDLE phToken);
    197 
    198 
    199 #define USERNAME_LENGTH         20
    200 #define CLIENTNAME_LENGTH       20
    201 #define CLIENTADDRESS_LENGTH    30
    202 #define WINSTATIONNAME_LENGTH   32
    203 #define DOMAIN_LENGTH           17
    204 
    205 #if (_WIN32_WINNT >= 0x0600)
    206 typedef struct _WTSCLIENTW {
    207   WCHAR   ClientName[CLIENTNAME_LENGTH + 1];
    208   WCHAR   Domain[DOMAIN_LENGTH + 1 ];
    209   WCHAR   UserName[USERNAME_LENGTH + 1];
    210   WCHAR   WorkDirectory[MAX_PATH + 1];
    211   WCHAR   InitialProgram[MAX_PATH + 1];
    212   BYTE    EncryptionLevel;
    213   ULONG   ClientAddressFamily;
    214   USHORT  ClientAddress[CLIENTADDRESS_LENGTH + 1];
    215   USHORT  HRes;
    216   USHORT  VRes;
    217   USHORT  ColorDepth;
    218   WCHAR   ClientDirectory[MAX_PATH + 1];
    219   ULONG   ClientBuildNumber;
    220   ULONG   ClientHardwareId;
    221   USHORT  ClientProductId;
    222   USHORT  OutBufCountHost;
    223   USHORT  OutBufCountClient;
    224   USHORT  OutBufLength;
    225   WCHAR     DeviceId[MAX_PATH + 1];
    226 } WTSCLIENTW, *PWTSCLIENTW;
    227 
    228 typedef struct _WTSCLIENTA {
    229   CHAR   ClientName[CLIENTNAME_LENGTH + 1];
    230   CHAR   Domain[DOMAIN_LENGTH + 1 ];
    231   CHAR   UserName[USERNAME_LENGTH + 1];
    232   CHAR   WorkDirectory[MAX_PATH + 1];
    233   CHAR   InitialProgram[MAX_PATH + 1];
    234   BYTE    EncryptionLevel;
    235   ULONG   ClientAddressFamily;
    236   USHORT  ClientAddress[CLIENTADDRESS_LENGTH + 1];
    237   USHORT  HRes;
    238   USHORT  VRes;
    239   USHORT  ColorDepth;
    240   CHAR   ClientDirectory[MAX_PATH + 1];
    241   ULONG   ClientBuildNumber;
    242   ULONG   ClientHardwareId;
    243   USHORT  ClientProductId;
    244   USHORT  OutBufCountHost;
    245   USHORT  OutBufCountClient;
    246   USHORT  OutBufLength;
    247   CHAR     DeviceId[MAX_PATH + 1];
    248 } WTSCLIENTA, *PWTSCLIENTA;
    249 
    250 __MINGW_TYPEDEF_AW(WTSCLIENT)
    251 __MINGW_TYPEDEF_AW(PWTSCLIENT)
    252 
    253 typedef struct _WTSINFOW {
    254   WTS_CONNECTSTATE_CLASS State;
    255   DWORD                  SessionId;
    256   DWORD                  IncomingBytes;
    257   DWORD                  OutgoingBytes;
    258   DWORD                  IncomingCompressedBytes;
    259   DWORD                  OutgoingCompressedBytes;
    260   WCHAR                  WinStationName[WINSTATIONNAME_LENGTH];
    261   WCHAR                  Domain[DOMAIN_LENGTH];
    262   WCHAR                  UserName[USERNAME_LENGTH+1];
    263   LARGE_INTEGER          ConnectTime;
    264   LARGE_INTEGER          DisconnectTime;
    265   LARGE_INTEGER          LastInputTime;
    266   LARGE_INTEGER          LogonTime;
    267   LARGE_INTEGER          CurrentTime;
    268 } WTSINFOW, *PWTSINFOW;
    269 
    270 typedef struct _WTSINFOA {
    271   WTS_CONNECTSTATE_CLASS State;
    272   DWORD                  SessionId;
    273   DWORD                  IncomingBytes;
    274   DWORD                  OutgoingBytes;
    275   DWORD                  IncomingCompressedBytes;
    276   DWORD                  OutgoingCompressedBytes;
    277   CHAR                   WinStationName[WINSTATIONNAME_LENGTH];
    278   CHAR                   Domain[DOMAIN_LENGTH];
    279   CHAR                   UserName[USERNAME_LENGTH+1];
    280   LARGE_INTEGER          ConnectTime;
    281   LARGE_INTEGER          DisconnectTime;
    282   LARGE_INTEGER          LastInputTime;
    283   LARGE_INTEGER          LogonTime;
    284   LARGE_INTEGER          CurrentTime;
    285 } WTSINFOA, *PWTSINFOA;
    286 
    287 __MINGW_TYPEDEF_AW(WTSINFO)
    288 __MINGW_TYPEDEF_AW(PWTSINFO)
    289 
    290 WINBOOL WINAPI WTSConnectSessionA(
    291   ULONG LogonId,
    292   ULONG TargetLogonId,
    293   PSTR   pPassword,
    294   WINBOOL bWait
    295 );
    296 
    297 WINBOOL WINAPI WTSConnectSessionW(
    298   ULONG LogonId,
    299   ULONG TargetLogonId,
    300   PWSTR  pPassword,
    301   WINBOOL bWait
    302 );
    303 
    304 WINBOOL WTSRegisterSessionNotificationEx(
    305   HANDLE hServer,
    306   HWND hWnd,
    307   DWORD dwFlags
    308 );
    309 
    310 WINBOOL WINAPI WTSStartRemoteControlSessionA(
    311   LPSTR pTargetServerName,
    312   ULONG TargetLogonId,
    313   BYTE HotkeyVk,
    314   USHORT HotkeyModifiers
    315 );
    316 
    317 WINBOOL WINAPI WTSStartRemoteControlSessionW(
    318   LPWSTR pTargetServerName,
    319   ULONG TargetLogonId,
    320   BYTE HotkeyVk,
    321   USHORT HotkeyModifiers
    322 );
    323 
    324 #define WTSStartRemoteControlSession __MINGW_NAME_AW(WTSStartRemoteControlSession)
    325 #define WTSConnectSession __MINGW_NAME_AW(WTSConnectSession)
    326 
    327 WINBOOL WINAPI WTSStopRemoteControlSession(
    328   ULONG LogonId
    329 );
    330 
    331 WINBOOL WINAPI WTSUnRegisterSessionNotificationEx(
    332   HANDLE hServer,
    333   HWND hWnd
    334 );
    335 
    336 HANDLE WINAPI WTSVirtualChannelOpenEx(
    337   DWORD SessionId,
    338   LPSTR pVirtualName,
    339   DWORD flags
    340 );
    341 
    342 #endif /*(_WIN32_WINNT >= 0x0600)*/
    343 
    344 #ifdef __cplusplus
    345 }
    346 #endif
    347 #endif
    348