66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
#include "../Shared/TriggerProtocol.h"
|
|
|
|
#include <windows.h>
|
|
#include <wtsapi32.h>
|
|
|
|
#include <cwchar>
|
|
#include <stdlib.h>
|
|
|
|
namespace
|
|
{
|
|
enum class ExitCode : int
|
|
{
|
|
Success = 0,
|
|
ChannelOpenFailed = 10,
|
|
WriteFailed = 11,
|
|
PartialWrite = 12
|
|
};
|
|
|
|
void DebugError(const wchar_t* step, DWORD error)
|
|
{
|
|
wchar_t buffer[256]{};
|
|
swprintf_s(buffer, _countof(buffer), L"PlandentRdpClientTrigger: %s fehlgeschlagen, Win32=%lu\n", step, error);
|
|
OutputDebugStringW(buffer);
|
|
}
|
|
}
|
|
|
|
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, PWSTR, int)
|
|
{
|
|
// WTS_CURRENT_SESSION stellt sicher, dass ausschließlich der Client der
|
|
// RDP-Sitzung angesprochen wird, in der diese EXE ausgeführt wird.
|
|
HANDLE channel = WTSVirtualChannelOpenEx(
|
|
WTS_CURRENT_SESSION,
|
|
const_cast<LPSTR>(hook::protocol::kChannelName),
|
|
WTS_CHANNEL_OPTION_DYNAMIC | WTS_CHANNEL_OPTION_DYNAMIC_PRI_MED);
|
|
|
|
if (channel == nullptr)
|
|
{
|
|
DebugError(L"WTSVirtualChannelOpenEx", GetLastError());
|
|
return static_cast<int>(ExitCode::ChannelOpenFailed);
|
|
}
|
|
|
|
ULONG bytesWritten = 0;
|
|
BOOL written = WTSVirtualChannelWrite(
|
|
channel,
|
|
const_cast<PCHAR>(hook::protocol::kStartMessage),
|
|
static_cast<ULONG>(hook::protocol::kStartMessageLength),
|
|
&bytesWritten);
|
|
|
|
DWORD writeError = written ? ERROR_SUCCESS : GetLastError();
|
|
WTSVirtualChannelClose(channel);
|
|
|
|
if (!written)
|
|
{
|
|
DebugError(L"WTSVirtualChannelWrite", writeError);
|
|
return static_cast<int>(ExitCode::WriteFailed);
|
|
}
|
|
|
|
if (bytesWritten != static_cast<ULONG>(hook::protocol::kStartMessageLength))
|
|
{
|
|
OutputDebugStringW(L"PlandentRdpClientTrigger: Trigger-Nachricht wurde nur teilweise geschrieben.\n");
|
|
return static_cast<int>(ExitCode::PartialWrite);
|
|
}
|
|
|
|
return static_cast<int>(ExitCode::Success);
|
|
}
|