mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-26 06:31:03 +03:00
Feat: Windows connect to a specific user session (#6825)
* feat windows connect to specific user session Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * fix import Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * fix multiple user session fields Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * fix build Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * fix build Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * fix file transfer Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * fix text color on light theme Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * feat windows connect to specific user session code changes and sciter support Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * update texts Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * fix sciter selected user session Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * add translations Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * Use Y,N options * feat windows specific user code changes Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * Update dialog.dart * Update connection.rs * Update connection.rs * feat windows specific user code changes Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * fix sciter Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * use lr.union Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * remove unused peer options Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * select user only when authorised and no existing connection Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * check for multiple users only once Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * optimise and add check for client version Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * use misc option message Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * update rdp user session proto Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * fix show cm on user session Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * Update pl.rs * update on_message Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * fix cm Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * remove user_session_id Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * fix cm Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> * fix multiple connections Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com> --------- Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <shlobj.h> // NOLINT(build/include_order)
|
||||
#include <userenv.h>
|
||||
#include <versionhelpers.h>
|
||||
#include <vector>
|
||||
|
||||
void flog(char const *fmt, ...)
|
||||
{
|
||||
@@ -433,6 +434,74 @@ extern "C"
|
||||
return nout;
|
||||
}
|
||||
|
||||
uint32_t get_current_process_session_id()
|
||||
{
|
||||
DWORD sessionId = 0;
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
if (hProcess) {
|
||||
ProcessIdToSessionId(GetCurrentProcessId(), &sessionId);
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
uint32_t get_session_user_info(PWSTR bufin, uint32_t nin, BOOL rdp, uint32_t id)
|
||||
{
|
||||
uint32_t nout = 0;
|
||||
PWSTR buf = NULL;
|
||||
DWORD n = 0;
|
||||
if (WTSQuerySessionInformationW(WTS_CURRENT_SERVER_HANDLE, id, WTSUserName, &buf, &n))
|
||||
{
|
||||
if (buf)
|
||||
{
|
||||
nout = min(nin, n);
|
||||
memcpy(bufin, buf, nout);
|
||||
WTSFreeMemory(buf);
|
||||
}
|
||||
}
|
||||
return nout;
|
||||
}
|
||||
|
||||
void get_available_session_ids(PWSTR buf, uint32_t bufSize, BOOL include_rdp) {
|
||||
std::vector<std::wstring> sessionIds;
|
||||
PWTS_SESSION_INFOA pInfos;
|
||||
DWORD count;
|
||||
|
||||
if (WTSEnumerateSessionsA(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pInfos, &count)) {
|
||||
for (DWORD i = 0; i < count; i++) {
|
||||
auto info = pInfos[i];
|
||||
auto rdp = "rdp";
|
||||
auto nrdp = strlen(rdp);
|
||||
if (info.State == WTSActive) {
|
||||
if (info.pWinStationName == NULL)
|
||||
continue;
|
||||
if (info.SessionId == 65536 || info.SessionId == 655)
|
||||
continue;
|
||||
|
||||
if (!stricmp(info.pWinStationName, "console")){
|
||||
sessionIds.push_back(std::wstring(L"Console:") + std::to_wstring(info.SessionId));
|
||||
}
|
||||
else if (include_rdp && !strnicmp(info.pWinStationName, rdp, nrdp)) {
|
||||
sessionIds.push_back(std::wstring(L"RDP:") + std::to_wstring(info.SessionId));
|
||||
}
|
||||
}
|
||||
}
|
||||
WTSFreeMemory(pInfos);
|
||||
}
|
||||
|
||||
std::wstring tmpStr;
|
||||
for (size_t i = 0; i < sessionIds.size(); i++) {
|
||||
if (i > 0) {
|
||||
tmpStr += L",";
|
||||
}
|
||||
tmpStr += sessionIds[i];
|
||||
}
|
||||
|
||||
if (buf && !tmpStr.empty() && tmpStr.size() < bufSize) {
|
||||
memcpy(buf, tmpStr.c_str(), (tmpStr.size() + 1) * sizeof(wchar_t));
|
||||
}
|
||||
}
|
||||
|
||||
BOOL has_rdp_service()
|
||||
{
|
||||
PWTS_SESSION_INFOA pInfos;
|
||||
|
||||
Reference in New Issue
Block a user