Skip to content

Commit d45f651

Browse files
committed
Connect with configuation for SynthRdp.
1 parent d0db495 commit d45f651

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

SynthRdp/SynthRdp.cpp

+39-5
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ EXTERN_C HANDLE WINAPI VmbusPipeClientTryOpenChannel(
4545

4646
namespace
4747
{
48-
static std::string g_ServerHost = "127.0.0.1";
49-
static std::string g_ServerPort = "3389";
50-
5148
static SERVICE_STATUS_HANDLE volatile g_ServiceStatusHandle = nullptr;
5249
static bool volatile g_ServiceIsRunning = true;
5350
}
@@ -56,6 +53,43 @@ SOCKET SynthRdpConnectToServer()
5653
{
5754
SOCKET Result = INVALID_SOCKET;
5855

56+
std::string ServerHost = "127.0.0.1";
57+
{
58+
std::wstring Buffer(32767, L'\0');
59+
DWORD Length = static_cast<DWORD>(Buffer.size());
60+
if (ERROR_SUCCESS == ::RegGetValueW(
61+
HKEY_LOCAL_MACHINE,
62+
L"SYSTEM\\CurrentControlSet\\Services\\"
63+
L"SynthRdp\\Configurations",
64+
L"ServerHost",
65+
RRF_RT_REG_SZ | RRF_SUBKEY_WOW6464KEY,
66+
nullptr,
67+
const_cast<wchar_t*>(Buffer.c_str()),
68+
&Length))
69+
{
70+
Buffer.resize(std::wcslen(Buffer.c_str()));
71+
ServerHost = Mile::ToString(CP_UTF8, Buffer);
72+
}
73+
}
74+
75+
std::string ServerPort = "3389";
76+
{
77+
DWORD Data = 0;
78+
DWORD Length = sizeof(DWORD);
79+
if (ERROR_SUCCESS == ::RegGetValueW(
80+
HKEY_LOCAL_MACHINE,
81+
L"SYSTEM\\CurrentControlSet\\Services\\"
82+
L"SynthRdp\\Configurations",
83+
L"ServerPort",
84+
RRF_RT_REG_DWORD | RRF_SUBKEY_WOW6464KEY,
85+
nullptr,
86+
&Data,
87+
&Length))
88+
{
89+
ServerPort = Mile::FormatString("%hu", Data);
90+
}
91+
}
92+
5993
int LastError = 0;
6094

6195
addrinfo AddressHints = { 0 };
@@ -64,8 +98,8 @@ SOCKET SynthRdpConnectToServer()
6498
AddressHints.ai_protocol = IPPROTO_TCP;
6599
addrinfo* AddressInfo = nullptr;
66100
LastError = ::getaddrinfo(
67-
g_ServerHost.c_str(),
68-
g_ServerPort.c_str(),
101+
ServerHost.c_str(),
102+
ServerPort.c_str(),
69103
&AddressHints,
70104
&AddressInfo);
71105
if (0 == LastError)

0 commit comments

Comments
 (0)