2013-08-20 03:18:31 +04:00
|
|
|
/**
|
|
|
|
* WinPR: Windows Portable Runtime
|
|
|
|
* Windows Terminal Services API
|
|
|
|
*
|
|
|
|
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
2013-09-17 01:10:27 +04:00
|
|
|
#include <winpr/synch.h>
|
2013-08-20 03:18:31 +04:00
|
|
|
|
|
|
|
#include <winpr/wtsapi.h>
|
|
|
|
|
2013-08-20 23:22:31 +04:00
|
|
|
/**
|
|
|
|
* Remote Desktop Services API Functions:
|
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/desktop/aa383464/
|
|
|
|
*/
|
|
|
|
|
2014-02-17 05:41:19 +04:00
|
|
|
static PWtsApiFunctionTable g_WtsApi = NULL;
|
2014-02-17 04:38:12 +04:00
|
|
|
|
2013-08-20 03:18:31 +04:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
2013-08-23 06:36:37 +04:00
|
|
|
BOOL WTSStartRemoteControlSessionW(LPWSTR pTargetServerName, ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->StartRemoteControlSessionW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->StartRemoteControlSessionW(pTargetServerName, TargetLogonId, HotkeyVk, HotkeyModifiers);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
2013-08-20 03:18:31 +04:00
|
|
|
|
2013-08-23 06:36:37 +04:00
|
|
|
BOOL WTSStartRemoteControlSessionA(LPSTR pTargetServerName, ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->StartRemoteControlSessionA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->StartRemoteControlSessionA(pTargetServerName, TargetLogonId, HotkeyVk, HotkeyModifiers);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2013-08-23 06:36:37 +04:00
|
|
|
BOOL WTSStopRemoteControlSession(ULONG LogonId)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->StopRemoteControlSession)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->StopRemoteControlSession(LogonId);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2013-08-23 08:06:22 +04:00
|
|
|
BOOL WTSConnectSessionW(ULONG LogonId, ULONG TargetLogonId, PWSTR pPassword, BOOL bWait)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->ConnectSessionW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->ConnectSessionW(LogonId, TargetLogonId, pPassword, bWait);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2013-08-23 08:06:22 +04:00
|
|
|
BOOL WTSConnectSessionA(ULONG LogonId, ULONG TargetLogonId, PSTR pPassword, BOOL bWait)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->ConnectSessionA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->ConnectSessionA(LogonId, TargetLogonId, pPassword, bWait);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSEnumerateServersW(LPWSTR pDomainName, DWORD Reserved, DWORD Version, PWTS_SERVER_INFOW* ppServerInfo, DWORD* pCount)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->EnumerateServersW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->EnumerateServersW(pDomainName, Reserved, Version, ppServerInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSEnumerateServersA(LPSTR pDomainName, DWORD Reserved, DWORD Version, PWTS_SERVER_INFOA* ppServerInfo, DWORD* pCount)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->EnumerateServersA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->EnumerateServersA(pDomainName, Reserved, Version, ppServerInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE WTSOpenServerW(LPWSTR pServerName)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->OpenServerW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->OpenServerW(pServerName);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE WTSOpenServerA(LPSTR pServerName)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->OpenServerA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->OpenServerA(pServerName);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE WTSOpenServerExW(LPWSTR pServerName)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->OpenServerExW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->OpenServerExW(pServerName);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE WTSOpenServerExA(LPSTR pServerName)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->OpenServerExA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->OpenServerExA(pServerName);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID WTSCloseServer(HANDLE hServer)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->CloseServer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_WtsApi->CloseServer(hServer);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSEnumerateSessionsW(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_SESSION_INFOW* ppSessionInfo, DWORD* pCount)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->EnumerateSessionsW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->EnumerateSessionsW(hServer, Reserved, Version, ppSessionInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSEnumerateSessionsA(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_SESSION_INFOA* ppSessionInfo, DWORD* pCount)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->EnumerateSessionsA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->EnumerateSessionsA(hServer, Reserved, Version, ppSessionInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSEnumerateSessionsExW(HANDLE hServer, DWORD* pLevel, DWORD Filter, PWTS_SESSION_INFO_1W* ppSessionInfo, DWORD* pCount)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->EnumerateSessionsExW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->EnumerateSessionsExW(hServer, pLevel, Filter, ppSessionInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSEnumerateSessionsExA(HANDLE hServer, DWORD* pLevel, DWORD Filter, PWTS_SESSION_INFO_1A* ppSessionInfo, DWORD* pCount)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->EnumerateSessionsExA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->EnumerateSessionsExA(hServer, pLevel, Filter, ppSessionInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSEnumerateProcessesW(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_PROCESS_INFOW* ppProcessInfo, DWORD* pCount)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->EnumerateProcessesW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->EnumerateProcessesW(hServer, Reserved, Version, ppProcessInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSEnumerateProcessesA(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_PROCESS_INFOA* ppProcessInfo, DWORD* pCount)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->EnumerateProcessesA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->EnumerateProcessesA(hServer, Reserved, Version, ppProcessInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSTerminateProcess(HANDLE hServer, DWORD ProcessId, DWORD ExitCode)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->TerminateProcess)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->TerminateProcess(hServer, ProcessId, ExitCode);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSQuerySessionInformationW(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass, LPWSTR* ppBuffer, DWORD* pBytesReturned)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->QuerySessionInformationW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->QuerySessionInformationW(hServer, SessionId, WTSInfoClass, ppBuffer, pBytesReturned);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSQuerySessionInformationA(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer, DWORD* pBytesReturned)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->QuerySessionInformationA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->QuerySessionInformationA(hServer, SessionId, WTSInfoClass, ppBuffer, pBytesReturned);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSQueryUserConfigW(LPWSTR pServerName, LPWSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPWSTR* ppBuffer, DWORD* pBytesReturned)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->QueryUserConfigW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->QueryUserConfigW(pServerName, pUserName, WTSConfigClass, ppBuffer, pBytesReturned);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSQueryUserConfigA(LPSTR pServerName, LPSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPSTR* ppBuffer, DWORD* pBytesReturned)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->QueryUserConfigA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->QueryUserConfigA(pServerName, pUserName, WTSConfigClass, ppBuffer, pBytesReturned);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSSetUserConfigW(LPWSTR pServerName, LPWSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPWSTR pBuffer, DWORD DataLength)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->SetUserConfigW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->SetUserConfigW(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSSetUserConfigA(LPSTR pServerName, LPSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPSTR pBuffer, DWORD DataLength)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->SetUserConfigA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->SetUserConfigA(pServerName, pUserName, WTSConfigClass, pBuffer, DataLength);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSSendMessageW(HANDLE hServer, DWORD SessionId, LPWSTR pTitle, DWORD TitleLength,
|
|
|
|
LPWSTR pMessage, DWORD MessageLength, DWORD Style, DWORD Timeout, DWORD* pResponse, BOOL bWait)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->SendMessageW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->SendMessageW(hServer, SessionId, pTitle, TitleLength,
|
2013-08-23 08:06:22 +04:00
|
|
|
pMessage, MessageLength, Style, Timeout, pResponse, bWait);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSSendMessageA(HANDLE hServer, DWORD SessionId, LPSTR pTitle, DWORD TitleLength,
|
|
|
|
LPSTR pMessage, DWORD MessageLength, DWORD Style, DWORD Timeout, DWORD* pResponse, BOOL bWait)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->SendMessageA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->SendMessageA(hServer, SessionId, pTitle, TitleLength,
|
|
|
|
pMessage, MessageLength, Style, Timeout, pResponse, bWait);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSDisconnectSession(HANDLE hServer, DWORD SessionId, BOOL bWait)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->DisconnectSession)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->DisconnectSession(hServer, SessionId, bWait);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSLogoffSession(HANDLE hServer, DWORD SessionId, BOOL bWait)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->LogoffSession)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->LogoffSession(hServer, SessionId, bWait);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSShutdownSystem(HANDLE hServer, DWORD ShutdownFlag)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->ShutdownSystem)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->ShutdownSystem(hServer, ShutdownFlag);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSWaitSystemEvent(HANDLE hServer, DWORD EventMask, DWORD* pEventFlags)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->WaitSystemEvent)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->WaitSystemEvent(hServer, EventMask, pEventFlags);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->VirtualChannelOpen)
|
|
|
|
return FALSE;
|
2013-08-23 06:36:37 +04:00
|
|
|
|
2014-02-17 04:38:12 +04:00
|
|
|
return g_WtsApi->VirtualChannelOpen(hServer, SessionId, pVirtualName);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->VirtualChannelOpenEx)
|
|
|
|
return FALSE;
|
2013-08-23 06:36:37 +04:00
|
|
|
|
2014-02-17 04:38:12 +04:00
|
|
|
return g_WtsApi->VirtualChannelOpenEx(SessionId, pVirtualName, flags);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSVirtualChannelClose(HANDLE hChannelHandle)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->VirtualChannelClose)
|
2013-08-23 03:20:59 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2014-02-17 04:38:12 +04:00
|
|
|
return g_WtsApi->VirtualChannelClose(hChannelHandle);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut, PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->VirtualChannelRead)
|
2013-08-23 03:20:59 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2014-02-17 04:38:12 +04:00
|
|
|
return g_WtsApi->VirtualChannelRead(hChannelHandle, TimeOut, Buffer, BufferSize, pBytesRead);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG Length, PULONG pBytesWritten)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->VirtualChannelWrite)
|
2013-08-23 03:20:59 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2014-02-17 04:38:12 +04:00
|
|
|
return g_WtsApi->VirtualChannelWrite(hChannelHandle, Buffer, Length, pBytesWritten);
|
2013-08-23 03:20:59 +04:00
|
|
|
}
|
|
|
|
|
2014-02-17 04:38:12 +04:00
|
|
|
BOOL WTSVirtualChannelPurgeInput(HANDLE hChannelHandle)
|
2013-08-23 03:20:59 +04:00
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->VirtualChannelPurgeInput)
|
2013-08-23 03:20:59 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2014-02-17 04:38:12 +04:00
|
|
|
return g_WtsApi->VirtualChannelPurgeInput(hChannelHandle);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSVirtualChannelPurgeOutput(HANDLE hChannelHandle)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->VirtualChannelPurgeOutput)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->VirtualChannelPurgeOutput(hChannelHandle);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass, PVOID* ppBuffer, DWORD* pBytesReturned)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->VirtualChannelQuery)
|
2013-08-23 03:20:59 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2014-02-17 04:38:12 +04:00
|
|
|
return g_WtsApi->VirtualChannelQuery(hChannelHandle, WtsVirtualClass, ppBuffer, pBytesReturned);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID WTSFreeMemory(PVOID pMemory)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->FreeMemory)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_WtsApi->FreeMemory(pMemory);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSFreeMemoryExW(WTS_TYPE_CLASS WTSTypeClass, PVOID pMemory, ULONG NumberOfEntries)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->FreeMemoryExW)
|
|
|
|
return FALSE;
|
2013-08-23 06:36:37 +04:00
|
|
|
|
2014-02-17 04:38:12 +04:00
|
|
|
return g_WtsApi->FreeMemoryExW(WTSTypeClass, pMemory, NumberOfEntries);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSFreeMemoryExA(WTS_TYPE_CLASS WTSTypeClass, PVOID pMemory, ULONG NumberOfEntries)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->FreeMemoryExA)
|
|
|
|
return FALSE;
|
2013-08-23 06:36:37 +04:00
|
|
|
|
2014-02-17 04:38:12 +04:00
|
|
|
return g_WtsApi->FreeMemoryExA(WTSTypeClass, pMemory, NumberOfEntries);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2013-08-23 08:06:22 +04:00
|
|
|
BOOL WTSRegisterSessionNotification(HWND hWnd, DWORD dwFlags)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->RegisterSessionNotification)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->RegisterSessionNotification(hWnd, dwFlags);
|
2013-08-23 08:06:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSUnRegisterSessionNotification(HWND hWnd)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->UnRegisterSessionNotification)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->UnRegisterSessionNotification(hWnd);
|
2013-08-23 08:06:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd, DWORD dwFlags)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->RegisterSessionNotificationEx)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->RegisterSessionNotificationEx(hServer, hWnd, dwFlags);
|
2013-08-23 08:06:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSUnRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->UnRegisterSessionNotificationEx)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->UnRegisterSessionNotificationEx(hServer, hWnd);
|
2013-08-23 08:06:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSQueryUserToken(ULONG SessionId, PHANDLE phToken)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->QueryUserToken)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->QueryUserToken(SessionId, phToken);
|
2013-08-23 08:06:22 +04:00
|
|
|
}
|
|
|
|
|
2013-08-20 04:38:43 +04:00
|
|
|
BOOL WTSEnumerateProcessesExW(HANDLE hServer, DWORD* pLevel, DWORD SessionId, LPWSTR* ppProcessInfo, DWORD* pCount)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->EnumerateProcessesExW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->EnumerateProcessesExW(hServer, pLevel, SessionId, ppProcessInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSEnumerateProcessesExA(HANDLE hServer, DWORD* pLevel, DWORD SessionId, LPSTR* ppProcessInfo, DWORD* pCount)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->EnumerateProcessesExA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->EnumerateProcessesExA(hServer, pLevel, SessionId, ppProcessInfo, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSEnumerateListenersW(HANDLE hServer, PVOID pReserved, DWORD Reserved, PWTSLISTENERNAMEW pListeners, DWORD* pCount)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->EnumerateListenersW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->EnumerateListenersW(hServer, pReserved, Reserved, pListeners, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSEnumerateListenersA(HANDLE hServer, PVOID pReserved, DWORD Reserved, PWTSLISTENERNAMEA pListeners, DWORD* pCount)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->EnumerateListenersA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->EnumerateListenersA(hServer, pReserved, Reserved, pListeners, pCount);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSQueryListenerConfigW(HANDLE hServer, PVOID pReserved, DWORD Reserved, LPWSTR pListenerName, PWTSLISTENERCONFIGW pBuffer)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->QueryListenerConfigW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->QueryListenerConfigW(hServer, pReserved, Reserved, pListenerName, pBuffer);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSQueryListenerConfigA(HANDLE hServer, PVOID pReserved, DWORD Reserved, LPSTR pListenerName, PWTSLISTENERCONFIGA pBuffer)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->QueryListenerConfigA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->QueryListenerConfigA(hServer, pReserved, Reserved, pListenerName, pBuffer);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
2013-08-20 04:58:42 +04:00
|
|
|
BOOL WTSCreateListenerW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
LPWSTR pListenerName, PWTSLISTENERCONFIGW pBuffer, DWORD flag)
|
2013-08-20 04:38:43 +04:00
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->CreateListenerW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->CreateListenerW(hServer, pReserved, Reserved, pListenerName, pBuffer, flag);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSCreateListenerA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
LPSTR pListenerName, PWTSLISTENERCONFIGA pBuffer, DWORD flag)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->CreateListenerA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->CreateListenerA(hServer, pReserved, Reserved, pListenerName, pBuffer, flag);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSSetListenerSecurityW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
LPWSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->SetListenerSecurityW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->SetListenerSecurityW(hServer, pReserved, Reserved,
|
|
|
|
pListenerName, SecurityInformation, pSecurityDescriptor);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSSetListenerSecurityA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
LPSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->SetListenerSecurityA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->SetListenerSecurityA(hServer, pReserved, Reserved,
|
|
|
|
pListenerName, SecurityInformation, pSecurityDescriptor);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSGetListenerSecurityW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
LPWSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, LPDWORD lpnLengthNeeded)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->GetListenerSecurityW)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->GetListenerSecurityW(hServer, pReserved, Reserved, pListenerName,
|
|
|
|
SecurityInformation, pSecurityDescriptor, nLength, lpnLengthNeeded);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSGetListenerSecurityA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
|
|
|
|
LPSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
|
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, LPDWORD lpnLengthNeeded)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->GetListenerSecurityA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->GetListenerSecurityA(hServer, pReserved, Reserved, pListenerName,
|
|
|
|
SecurityInformation, pSecurityDescriptor, nLength, lpnLengthNeeded);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSEnableChildSessions(BOOL bEnable)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->EnableChildSessions)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->EnableChildSessions(bEnable);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSIsChildSessionsEnabled(PBOOL pbEnabled)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->IsChildSessionsEnabled)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->IsChildSessionsEnabled(pbEnabled);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WTSGetChildSessionId(PULONG pSessionId)
|
|
|
|
{
|
2014-02-17 04:38:12 +04:00
|
|
|
if (!g_WtsApi || !g_WtsApi->GetChildSessionId)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return g_WtsApi->GetChildSessionId(pSessionId);
|
2013-08-20 04:38:43 +04:00
|
|
|
}
|
2013-08-20 03:18:31 +04:00
|
|
|
|
2014-02-17 05:12:45 +04:00
|
|
|
DWORD WTSGetActiveConsoleSessionId(void)
|
|
|
|
{
|
|
|
|
if (!g_WtsApi || !g_WtsApi->GetActiveConsoleSessionId)
|
|
|
|
return 0xFFFFFFFF;
|
|
|
|
|
|
|
|
return g_WtsApi->GetActiveConsoleSessionId();
|
|
|
|
}
|
|
|
|
|
2013-08-20 03:18:31 +04:00
|
|
|
#endif
|
2014-02-17 04:38:12 +04:00
|
|
|
|
|
|
|
BOOL WTSRegisterWtsApiFunctionTable(PWtsApiFunctionTable table)
|
|
|
|
{
|
|
|
|
g_WtsApi = table;
|
|
|
|
return TRUE;
|
|
|
|
}
|