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