1 /**
2  * @file wtsapi32.h
3  * Copyright 2012, 2013 MinGW.org project
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 #ifndef _WTSAPI32_H
25 #define _WTSAPI32_H
26 #pragma GCC system_header
27 #include <_mingw.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #if (_WIN32_WINNT >= _WIN32_WINNT_WIN2K)
34   // WTSWaitSystemEvent local server handle
35 #define WTS_CURRENT_SERVER_HANDLE 0
36 #define WTS_CURRENT_SESSION       ((DWORD)-1)
37 
38   // WTSWaitSystemEvent flags
39 #define WTS_EVENT_NONE				0x00000000
40 #define WTS_EVENT_CREATE			0x00000001
41 #define WTS_EVENT_DELETE			0x00000002
42 #define WTS_EVENT_RENAME			0x00000004
43 #define WTS_EVENT_CONNECT			0x00000008
44 #define WTS_EVENT_DISCONNECT		0x00000010
45 #define WTS_EVENT_LOGON				0x00000020
46 #define WTS_EVENT_LOGOFF			0x00000040
47 #define WTS_EVENT_STATECHANGE		0x00000080
48 #define WTS_EVENT_LICENSE			0x00000100
49 #define WTS_EVENT_ALL				0x7FFFFFFF
50 #define WTS_EVENT_FLUSH				0x80000000
51 
52 BOOL WINAPI WTSWaitSystemEvent(HANDLE hServer, DWORD EventMask, DWORD* pEventFlags);
53 BOOL WINAPI WTSDisconnectSession(HANDLE hServer, DWORD SessionId, BOOL bWait);
54 void WINAPI WTSFreeMemory(PVOID pMemory);
55 
56 #define WTSEnumerateSessions __AW(WTSEnumerateSessions)
57 #define WTSQuerySessionInformation __AW(WTSQuerySessionInformation)
58 
59 BOOL WTSSendMessageA(
60   HANDLE hServer,
61   DWORD SessionId,
62   LPSTR pTitle,
63   DWORD TitleLength,
64   LPSTR pMessage,
65   DWORD MessageLength,
66   DWORD Style,
67   DWORD Timeout,
68   DWORD *pResponse,
69   BOOL bWait
70 );
71 
72 BOOL WTSSendMessageW(
73   HANDLE hServer,
74   DWORD SessionId,
75   LPWSTR pTitle,
76   DWORD TitleLength,
77   LPWSTR pMessage,
78   DWORD MessageLength,
79   DWORD Style,
80   DWORD Timeout,
81   DWORD *pResponse,
82   BOOL bWait
83 );
84 
85 #define WTSSendMessage __AW(WTSSendMessage)
86 
87 BOOL WTSVirtualChannelClose(
88   HANDLE hChannelHandle
89 );
90 
91 HANDLE WTSVirtualChannelOpen(
92   HANDLE hServer,
93   DWORD SessionId,
94   LPSTR pVirtualName
95 );
96 
97 BOOL WTSVirtualChannelPurgeInput(
98   HANDLE hChannelHandle
99 );
100 
101 BOOL WTSVirtualChannelPurgeOutput(
102   HANDLE hChannelHandle
103 );
104 
105 BOOL WTSVirtualChannelRead(
106   HANDLE hChannelHandle,
107   ULONG TimeOut,
108   PCHAR Buffer,
109   ULONG BufferSize,
110   PULONG pBytesRead
111 );
112 
113 BOOL WTSVirtualChannelWrite(
114   HANDLE hChannelHandle,
115   PCHAR Buffer,
116   ULONG Length,
117   PULONG pBytesWritten
118 );
119 #endif /* _WIN32_WINNT >= _WIN32_WINNT_WIN2K */
120 
121 #if (_WIN32_WINNT >= _WIN32_WINNT_WINXP)
122   // session notification message
123 #define WM_WTSSESSION_CHANGE		0x02B1
124 
125 typedef enum _WTS_INFO_CLASS {
126   WTSInitialProgram       = 0,
127   WTSApplicationName      = 1,
128   WTSWorkingDirectory     = 2,
129   WTSOEMId                = 3,
130   WTSSessionId            = 4,
131   WTSUserName             = 5,
132   WTSWinStationName       = 6,
133   WTSDomainName           = 7,
134   WTSConnectState         = 8,
135   WTSClientBuildNumber    = 9,
136   WTSClientName           = 10,
137   WTSClientDirectory      = 11,
138   WTSClientProductId      = 12,
139   WTSClientHardwareId     = 13,
140   WTSClientAddress        = 14,
141   WTSClientDisplay        = 15,
142   WTSClientProtocolType   = 16,
143   WTSIdleTime             = 17,
144   WTSLogonTime            = 18,
145   WTSIncomingBytes        = 19,
146   WTSOutgoingBytes        = 20,
147   WTSIncomingFrames       = 21,
148   WTSOutgoingFrames       = 22,
149   WTSClientInfo           = 23,
150   WTSSessionInfo          = 24
151 } WTS_INFO_CLASS;
152 
153 typedef enum _WTS_CONNECTSTATE_CLASS {
154   WTSActive,
155   WTSConnected,
156   WTSConnectQuery,
157   WTSShadow,
158   WTSDisconnected,
159   WTSIdle,
160   WTSListen,
161   WTSReset,
162   WTSDown,
163   WTSInit
164 } WTS_CONNECTSTATE_CLASS;
165 
166 typedef enum _WTS_VIRTUAL_CLASS {
167   WTSVirtualClientData,
168   WTSVirtualFileHandle
169 } WTS_VIRTUAL_CLASS;
170 
171   // session notification message flags
172 #define WTS_CONSOLE_CONNECT			0x1
173 #define WTS_CONSOLE_DISCONNECT		0x2
174 #define WTS_REMOTE_CONNECT			0x3
175 #define WTS_REMOTE_DISCONNECT		0x4
176 #define WTS_SESSION_LOGON			0x5
177 #define WTS_SESSION_LOGOFF			0x6
178 #define WTS_SESSION_LOCK			0x7
179 #define WTS_SESSION_UNLOCK			0x8
180 #define WTS_SESSION_REMOTE_CONTROL	0x9
181 
182   // WTSRegisterSessionNotifiction flags
183 #define NOTIFY_FOR_THIS_SESSION		0
184 #define NOTIFY_FOR_ALL_SESSIONS		1
185 
186 BOOL WINAPI WTSRegisterSessionNotification(HWND hWnd, DWORD dwFlags);
187 BOOL WINAPI WTSUnRegisterSessionNotification(HWND hWnd);
188 BOOL WINAPI WTSQueryUserToken(ULONG SessionId, PHANDLE pToken);
189 
190 BOOL WTSVirtualChannelQuery(
191   HANDLE hChannelHandle,
192   WTS_VIRTUAL_CLASS WtsVirtualClass,
193   PVOID *ppBuffer,
194   DWORD *pBytesReturned
195 );
196 
197 typedef struct _WTS_SESSION_INFOW {
198   DWORD SessionId;
199   LPWSTR pWinStationName;
200   WTS_CONNECTSTATE_CLASS State;
201 } WTS_SESSION_INFOW, *PWTS_SESSION_INFOW;
202 
203 typedef struct _WTS_SESSION_INFOA {
204   DWORD SessionId;
205   LPSTR pWinStationName;
206   WTS_CONNECTSTATE_CLASS State;
207 } WTS_SESSION_INFOA, *PWTS_SESSION_INFOA;
208 
209 #define WTS_SESSION_INFO	__AW(WTS_SESSION_INFO)
210 #define PWTS_SESSION_INFO	__AW(PWTS_SESSION_INFO)
211 
212 BOOL WINAPI WTSQuerySessionInformationA(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass,
213                                 LPSTR *ppBuffer, DWORD *pBytesReturned);
214 BOOL WINAPI WTSQuerySessionInformationW(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass,
215                                 LPTSTR *ppBuffer, DWORD *pBytesReturned);
216 BOOL WINAPI WTSEnumerateSessionsW(HANDLE hServer, DWORD Reserved, DWORD Version,
217 				  PWTS_SESSION_INFOW *ppSessionInfo,
218 				  PDWORD pCount);
219 BOOL WINAPI WTSEnumerateSessionsA(HANDLE hServer, DWORD Reserved, DWORD Version,
220 				  PWTS_SESSION_INFOA *ppSessionInfo,
221 				  PDWORD pCount);
222 #endif /* _WIN32_WINNT >= _WIN32_WINNT_WINXP */
223 
224 #if _WIN32_WINNT >= _WIN32_WINNT_VISTA
225 HANDLE WTSVirtualChannelOpenEx(
226   DWORD SessionId,
227   LPSTR pVirtualName,
228   DWORD flags
229 );
230 #endif
231 
232 #ifdef __cplusplus
233 }
234 #endif
235 
236 #endif /* _WTSAPI32_H */
237