The OpenD Programming Language

1 /**
2  * Windows API header module
3  *
4  * Translated from MinGW-w64 API
5  *
6  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
7  * Source: $(DRUNTIMESRC core/sys/windows/_wtsapi32.d)
8  */
9 module core.sys.windows.wtsapi32;
10 version (Windows):
11 
12 version (ANSI) {} else version = Unicode;
13 pragma(lib, "wtsapi32");
14 import core.sys.windows.w32api;
15 import core.sys.windows.windef;
16 
17 enum {
18     WTS_CURRENT_SERVER        = null,
19     WTS_CURRENT_SERVER_HANDLE = null,
20     WTS_CURRENT_SERVER_NAME   = null
21 }
22 
23 enum DWORD WTS_CURRENT_SESSION = cast(DWORD) -1;
24 
25 enum {
26     IDTIMEOUT = 32000,
27     IDASYNC   = 32001
28 }
29 
30 enum {
31     WTS_WSD_LOGOFF     = 0x01,
32     WTS_WSD_SHUTDOWN   = 0x02,
33     WTS_WSD_REBOOT     = 0x04,
34     WTS_WSD_POWEROFF   = 0x08,
35     WTS_WSD_FASTREBOOT = 0x10
36 }
37 
38 enum WTS_CONNECTSTATE_CLASS {
39     WTSActive,
40     WTSConnected,
41     WTSConnectQuery,
42     WTSShadow,
43     WTSDisconnected,
44     WTSIdle,
45     WTSListen,
46     WTSReset,
47     WTSDown,
48     WTSInit
49 }
50 
51 struct WTS_SERVER_INFOW {
52     LPWSTR pServerName;
53 }
54 alias WTS_SERVER_INFOW* PWTS_SERVER_INFOW;
55 
56 struct WTS_SERVER_INFOA {
57     LPSTR pServerName;
58 }
59 alias WTS_SERVER_INFOA* PWTS_SERVER_INFOA;
60 
61 version (Unicode) {
62     alias WTS_SERVER_INFOW  WTS_SERVER_INFO;
63     alias PWTS_SERVER_INFOW PWTS_SERVER_INFO;
64 } else {
65     alias WTS_SERVER_INFOA  WTS_SERVER_INFO;
66     alias PWTS_SERVER_INFOA PWTS_SERVER_INFO;
67 }
68 
69 struct WTS_SESSION_INFOW {
70     DWORD SessionId;
71     LPWSTR pWinStationName;
72     WTS_CONNECTSTATE_CLASS State;
73 }
74 alias WTS_SESSION_INFOW* PWTS_SESSION_INFOW;
75 
76 struct WTS_SESSION_INFOA {
77     DWORD SessionId;
78     LPSTR pWinStationName;
79     WTS_CONNECTSTATE_CLASS State;
80 }
81 alias WTS_SESSION_INFOA* PWTS_SESSION_INFOA;
82 
83 version (Unicode) {
84     alias WTS_SESSION_INFOW  WTS_SESSION_INFO;
85     alias PWTS_SESSION_INFOW PWTS_SESSION_INFO;
86 } else {
87     alias WTS_SESSION_INFOA  WTS_SESSION_INFO;
88     alias PWTS_SESSION_INFOA PWTS_SESSION_INFO;
89 }
90 
91 struct WTS_PROCESS_INFOW {
92     DWORD SessionId;
93     DWORD ProcessId;
94     LPWSTR pProcessName;
95     PSID pUserSid;
96 }
97 alias WTS_PROCESS_INFOW* PWTS_PROCESS_INFOW;
98 
99 struct WTS_PROCESS_INFOA {
100     DWORD SessionId;
101     DWORD ProcessId;
102     LPSTR pProcessName;
103     PSID pUserSid;
104 }
105 alias WTS_PROCESS_INFOA* PWTS_PROCESS_INFOA;
106 
107 version (Unicode) {
108     alias WTS_PROCESS_INFOW  WTS_PROCESS_INFO;
109     alias PWTS_PROCESS_INFOW PWTS_PROCESS_INFO;
110 } else {
111     alias WTS_PROCESS_INFOA  WTS_PROCESS_INFO;
112     alias PWTS_PROCESS_INFOA PWTS_PROCESS_INFO;
113 }
114 
115 enum {
116     WTS_PROTOCOL_TYPE_CONSOLE,
117     WTS_PROTOCOL_TYPE_ICA,
118     WTS_PROTOCOL_TYPE_RDP
119 }
120 
121 enum WTS_INFO_CLASS {
122     WTSInitialProgram,
123     WTSApplicationName,
124     WTSWorkingDirectory,
125     WTSOEMId,
126     WTSSessionId,
127     WTSUserName,
128     WTSWinStationName,
129     WTSDomainName,
130     WTSConnectState,
131     WTSClientBuildNumber,
132     WTSClientName,
133     WTSClientDirectory,
134     WTSClientProductId,
135     WTSClientHardwareId,
136     WTSClientAddress,
137     WTSClientDisplay,
138     WTSClientProtocolType,
139     WTSIdleTime,
140     WTSLogonTime,
141     WTSIncomingBytes,
142     WTSOutgoingBytes,
143     WTSIncomingFrames,
144     WTSOutgoingFrames,
145     WTSClientInfo,
146     WTSSessionInfo, // = 24
147 }
148 
149 struct WTS_CLIENT_ADDRESS {
150     DWORD    AddressFamily;
151     BYTE[20] Address;
152 }
153 alias WTS_CLIENT_ADDRESS* PWTS_CLIENT_ADDRESS;
154 
155 struct WTS_CLIENT_DISPLAY {
156     DWORD HorizontalResolution;
157     DWORD VerticalResolution;
158     DWORD ColorDepth;
159 }
160 alias WTS_CLIENT_DISPLAY* PWTS_CLIENT_DISPLAY;
161 
162 enum WTS_CONFIG_CLASS {
163     WTSUserConfigInitialProgram,
164     WTSUserConfigWorkingDirectory,
165     WTSUserConfigfInheritInitialProgram,
166     WTSUserConfigfAllowLogonTerminalServer,
167     WTSUserConfigTimeoutSettingsConnections,
168     WTSUserConfigTimeoutSettingsDisconnections,
169     WTSUserConfigTimeoutSettingsIdle,
170     WTSUserConfigfDeviceClientDrives,
171     WTSUserConfigfDeviceClientPrinters,
172     WTSUserConfigfDeviceClientDefaultPrinter,
173     WTSUserConfigBrokenTimeoutSettings,
174     WTSUserConfigReconnectSettings,
175     WTSUserConfigModemCallbackSettings,
176     WTSUserConfigModemCallbackPhoneNumber,
177     WTSUserConfigShadowingSettings,
178     WTSUserConfigTerminalServerProfilePath,
179     WTSUserConfigTerminalServerHomeDir,
180     WTSUserConfigTerminalServerHomeDirDrive,
181     WTSUserConfigfTerminalServerRemoteHomeDir
182 }
183 
184 enum {
185     WTS_EVENT_NONE        = 0x0,
186     WTS_EVENT_CREATE      = 0x1,
187     WTS_EVENT_DELETE      = 0x2,
188     WTS_EVENT_RENAME      = 0x4,
189     WTS_EVENT_CONNECT     = 0x8,
190     WTS_EVENT_DISCONNECT  = 0x10,
191     WTS_EVENT_LOGON       = 0x20,
192     WTS_EVENT_LOGOFF      = 0x40,
193     WTS_EVENT_STATECHANGE = 0x80,
194     WTS_EVENT_LICENSE     = 0x100,
195     WTS_EVENT_ALL         = 0x7fffffff,
196     WTS_EVENT_FLUSH       = 0x80000000
197 }
198 
199 enum WTS_VIRTUAL_CLASS {
200     WTSVirtualClientData,
201     WTSVirtualFileHandle
202 }
203 
204 version (Unicode) {
205     alias WTSEnumerateServersW WTSEnumerateServers;
206     alias WTSOpenServerW WTSOpenServer;
207     alias WTSEnumerateSessionsW WTSEnumerateSessions;
208     alias WTSEnumerateProcessesW WTSEnumerateProcesses;
209     alias WTSQuerySessionInformationW WTSQuerySessionInformation;
210     alias WTSQueryUserConfigW WTSQueryUserConfig;
211     alias WTSSetUserConfigW WTSSetUserConfig;
212     alias WTSSendMessageW WTSSendMessage;
213 } else {
214     alias WTSEnumerateServersA WTSEnumerateServers;
215     alias WTSOpenServerA WTSOpenServer;
216     alias WTSEnumerateSessionsA WTSEnumerateSessions;
217     alias WTSEnumerateProcessesA WTSEnumerateProcesses;
218     alias WTSQuerySessionInformationA WTSQuerySessionInformation;
219     alias WTSQueryUserConfigA WTSQueryUserConfig;
220     alias WTSSetUserConfigA WTSSetUserConfig;
221     alias WTSSendMessageA WTSSendMessage;
222 }
223 
224 extern(Windows) {
225     WINBOOL WTSEnumerateServersW(LPWSTR pDomainName, DWORD Reserved, DWORD Version, PWTS_SERVER_INFOW* ppServerInfo, DWORD* pCount);
226     WINBOOL WTSEnumerateServersA(LPSTR pDomainName, DWORD Reserved, DWORD Version, PWTS_SERVER_INFOA* ppServerInfo, DWORD* pCount);
227     HANDLE WTSOpenServerW(LPWSTR pServerName);
228     HANDLE WTSOpenServerA(LPSTR pServerName);
229     VOID WTSCloseServer(HANDLE hServer);
230     WINBOOL WTSEnumerateSessionsW(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_SESSION_INFOW* ppSessionInfo, DWORD* pCount);
231     WINBOOL WTSEnumerateSessionsA(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_SESSION_INFOA* ppSessionInfo, DWORD* pCount);
232     WINBOOL WTSEnumerateProcessesW(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_PROCESS_INFOW* ppProcessInfo, DWORD* pCount);
233     WINBOOL WTSEnumerateProcessesA(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_PROCESS_INFOA* ppProcessInfo, DWORD* pCount);
234     WINBOOL WTSTerminateProcess(HANDLE hServer, DWORD ProcessId, DWORD ExitCode);
235     WINBOOL WTSQuerySessionInformationW(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass, LPWSTR* ppBuffer, DWORD* pBytesReturned);
236     WINBOOL WTSQuerySessionInformationA(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer, DWORD* pBytesReturned);
237     WINBOOL WTSQueryUserConfigW(LPWSTR pServerName, LPWSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPWSTR* ppBuffer, DWORD* pBytesReturned);
238     WINBOOL WTSQueryUserConfigA(LPSTR pServerName, LPSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPSTR* ppBuffer, DWORD* pBytesReturned);
239     WINBOOL WTSSetUserConfigW(LPWSTR pServerName, LPWSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPWSTR pBuffer, DWORD DataLength);
240     WINBOOL WTSSetUserConfigA(LPSTR pServerName, LPSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPSTR pBuffer, DWORD DataLength);
241     WINBOOL WTSSendMessageW(HANDLE hServer, DWORD SessionId, LPWSTR pTitle, DWORD TitleLength, LPWSTR pMessage, DWORD MessageLength, DWORD Style, DWORD Timeout, DWORD* pResponse, WINBOOL bWait);
242     WINBOOL WTSSendMessageA(HANDLE hServer, DWORD SessionId, LPSTR pTitle, DWORD TitleLength, LPSTR pMessage, DWORD MessageLength, DWORD Style, DWORD Timeout, DWORD* pResponse, WINBOOL bWait);
243     WINBOOL WTSDisconnectSession(HANDLE hServer, DWORD SessionId, WINBOOL bWait);
244     WINBOOL WTSLogoffSession(HANDLE hServer, DWORD SessionId, WINBOOL bWait);
245     WINBOOL WTSShutdownSystem(HANDLE hServer, DWORD ShutdownFlag);
246     WINBOOL WTSWaitSystemEvent(HANDLE hServer, DWORD EventMask, DWORD* pEventFlags);
247     HANDLE WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName);
248     WINBOOL WTSVirtualChannelClose(HANDLE hChannelHandle);
249     WINBOOL WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut, PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead);
250     WINBOOL WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG Length, PULONG pBytesWritten);
251     WINBOOL WTSVirtualChannelPurgeInput(HANDLE hChannelHandle);
252     WINBOOL WTSVirtualChannelPurgeOutput(HANDLE hChannelHandle);
253     WINBOOL WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS, PVOID* ppBuffer, DWORD* pBytesReturned);
254     VOID WTSFreeMemory(PVOID pMemory);
255 
256     WINBOOL WTSRegisterSessionNotification(HWND hWnd, DWORD dwFlags);
257     WINBOOL WTSUnRegisterSessionNotification(HWND hWnd);
258     WINBOOL WTSQueryUserToken(ULONG SessionId, PHANDLE phToken);
259 }
260 
261 enum {
262     NOTIFY_FOR_ALL_SESSIONS = 1,
263     NOTIFY_FOR_THIS_SESSION = 0
264 }
265 
266 enum {
267     USERNAME_LENGTH       = 20,
268     CLIENTNAME_LENGTH     = 20,
269     CLIENTADDRESS_LENGTH  = 30,
270     WINSTATIONNAME_LENGTH = 32,
271     DOMAIN_LENGTH         = 17
272 }
273 
274 static if (_WIN32_WINNT >= 0x600) {
275     struct WTSCLIENTW {
276         WCHAR[CLIENTNAME_LENGTH + 1]      ClientName = 0;
277         WCHAR[DOMAIN_LENGTH + 1]          Domain = 0;
278         WCHAR[USERNAME_LENGTH + 1]        UserName = 0;
279         WCHAR[MAX_PATH + 1]               WorkDirectory = 0;
280         WCHAR[MAX_PATH + 1]               InitialProgram = 0;
281         BYTE                              EncryptionLevel;
282         ULONG                             ClientAddressFamily;
283         USHORT[CLIENTADDRESS_LENGTH + 1]  ClientAddress;
284         USHORT                            HRes;
285         USHORT                            VRes;
286         USHORT                            ColorDepth;
287         WCHAR[MAX_PATH + 1]               ClientDirectory = 0;
288         ULONG                             ClientBuildNumber;
289         ULONG                             ClientHardwareId;
290         USHORT                            ClientProductId;
291         USHORT                            OutBufCountHost;
292         USHORT                            OutBufCountClient;
293         USHORT                            OutBufLength;
294         WCHAR[MAX_PATH + 1]               DeviceId = 0;
295     }
296     alias WTSCLIENTW* PWTSCLIENTW;
297 
298     struct WTSCLIENTA {
299         CHAR[CLIENTNAME_LENGTH + 1]       ClientName = 0;
300         CHAR[DOMAIN_LENGTH + 1 ]          Domain = 0;
301         CHAR[USERNAME_LENGTH + 1]         UserName = 0;
302         CHAR[MAX_PATH + 1]                WorkDirectory = 0;
303         CHAR[MAX_PATH + 1]                InitialProgram = 0;
304         BYTE                              EncryptionLevel;
305         ULONG                             ClientAddressFamily;
306         USHORT[CLIENTADDRESS_LENGTH + 1]  ClientAddress;
307         USHORT                            HRes;
308         USHORT                            VRes;
309         USHORT                            ColorDepth;
310         CHAR[MAX_PATH + 1]                ClientDirectory = 0;
311         ULONG                             ClientBuildNumber;
312         ULONG                             ClientHardwareId;
313         USHORT                            ClientProductId;
314         USHORT                            OutBufCountHost;
315         USHORT                            OutBufCountClient;
316         USHORT                            OutBufLength;
317         CHAR[MAX_PATH + 1]                DeviceId = 0;
318     }
319     alias WTSCLIENTA* PWTSCLIENTA;
320 
321     version (Unicode) {
322         alias WTSCLIENTW  WTSCLIENT;
323         alias PWTSCLIENTW PWTSCLIENT;
324     } else {
325         alias WTSCLIENTA  WTSCLIENT;
326         alias PWTSCLIENTA PWTSCLIENT;
327     }
328 
329     struct WTSINFOW {
330         WTS_CONNECTSTATE_CLASS       State;
331         DWORD                        SessionId;
332         DWORD                        IncomingBytes;
333         DWORD                        OutgoingBytes;
334         DWORD                        IncomingFrames;
335         DWORD                        OutgoingFrames;
336         DWORD                        IncomingCompressedBytes;
337         DWORD                        OutgoingCompressedBytes;
338         WCHAR[WINSTATIONNAME_LENGTH] WinStationName = 0;
339         WCHAR[DOMAIN_LENGTH]         Domain = 0;
340         WCHAR[USERNAME_LENGTH+1]     UserName = 0;
341         LARGE_INTEGER                ConnectTime;
342         LARGE_INTEGER                DisconnectTime;
343         LARGE_INTEGER                LastInputTime;
344         LARGE_INTEGER                LogonTime;
345         LARGE_INTEGER                CurrentTime;
346     }
347     alias WTSINFOW* PWTSINFOW;
348 
349     struct WTSINFOA {
350         WTS_CONNECTSTATE_CLASS      State;
351         DWORD                       SessionId;
352         DWORD                       IncomingBytes;
353         DWORD                       OutgoingBytes;
354         DWORD                       IncomingFrames;
355         DWORD                       OutgoingFrames;
356         DWORD                       IncomingCompressedBytes;
357         DWORD                       OutgoingCompressedBytes;
358         CHAR[WINSTATIONNAME_LENGTH] WinStationName = 0;
359         CHAR[DOMAIN_LENGTH]         Domain = 0;
360         CHAR[USERNAME_LENGTH+1]     UserName = 0;
361         LARGE_INTEGER               ConnectTime;
362         LARGE_INTEGER               DisconnectTime;
363         LARGE_INTEGER               LastInputTime;
364         LARGE_INTEGER               LogonTime;
365         LARGE_INTEGER               CurrentTime;
366     }
367     alias WTSINFOA* PWTSINFOA;
368 
369     version (Unicode) {
370         alias WTSINFOW  WTSINFO;
371         alias PWTSINFOW PWTSINFO;
372     } else {
373         alias WTSINFOA  WTSINFO;
374         alias PWTSINFOA PWTSINFO;
375     }
376 
377     extern(Windows) {
378         WINBOOL WTSConnectSessionA(
379             ULONG LogonId,
380             ULONG TargetLogonId,
381             PSTR   pPassword,
382             WINBOOL bWait
383         );
384 
385         WINBOOL WTSConnectSessionW(
386             ULONG LogonId,
387             ULONG TargetLogonId,
388             PWSTR  pPassword,
389             WINBOOL bWait
390         );
391 
392         WINBOOL WTSRegisterSessionNotificationEx(
393             HANDLE hServer,
394             HWND hWnd,
395             DWORD dwFlags
396         );
397 
398         WINBOOL WTSStartRemoteControlSessionA(
399             LPSTR pTargetServerName,
400             ULONG TargetLogonId,
401             BYTE HotkeyVk,
402             USHORT HotkeyModifiers
403         );
404 
405         WINBOOL WTSStartRemoteControlSessionW(
406             LPWSTR pTargetServerName,
407             ULONG TargetLogonId,
408             BYTE HotkeyVk,
409             USHORT HotkeyModifiers
410         );
411 
412         version (Unicode) {
413             alias WTSStartRemoteControlSessionW WTSStartRemoteControlSession;
414             alias WTSConnectSessionW WTSConnectSession;
415         } else {
416             alias WTSStartRemoteControlSessionA WTSStartRemoteControlSession;
417             alias WTSConnectSessionA WTSConnectSession;
418         }
419 
420         WINBOOL WTSStopRemoteControlSession(
421             ULONG LogonId
422         );
423 
424         WINBOOL WTSUnRegisterSessionNotificationEx(
425             HANDLE hServer,
426             HWND hWnd
427         );
428 
429         HANDLE WTSVirtualChannelOpenEx(
430             DWORD SessionId,
431             LPSTR pVirtualName,
432             DWORD flags
433         );
434     } /* extern(Windows) */
435 } /* static if (_WIN32_WINNT >= 0x600) */