【发布时间】:2017-05-24 14:40:34
【问题描述】:
我的应用程序通过 RDP 在 Windows 服务器上运行。在应用程序中,我想知道客户端(带有 RDP 会话)是否是移动设备。
是否可以获取客户端操作系统?
【问题讨论】:
我的应用程序通过 RDP 在 Windows 服务器上运行。在应用程序中,我想知道客户端(带有 RDP 会话)是否是移动设备。
是否可以获取客户端操作系统?
【问题讨论】:
有关当前用户连接的所有 RDP 环境变量的列表,请参阅下面的评论。
Citrix ICA 连接的注册位置是 HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\Ica\Session\\Connection\
子键 ClientProductID 和 ClientType 将参考连接的设备类型。
这里有一些基本的代码来获取远程会话,然后从 regedit 中获取会话信息。
// Prints out ICA or RDP session ID of current user & gets ICA session ClientType variable
using System;
using Microsoft.Win32;
namespace ViaRegedit
{
class Program03
{
static void Main(string[] args)
{
// Obtain an instance of RegistryKey for the CurrentUser registry
RegistryKey rkCurrentUser = Registry.CurrentUser;
// Obtain the test key (read-only) and display it.
RegistryKey rkTest = rkCurrentUser.OpenSubKey("Remote");
foreach (string valueName in rkTest.GetSubKeyNames())
{
//Getting path to RDP/Citrix session ID
string RDPICApath = "";
if (rkTest.OpenSubKey(valueName) != null && rkTest.OpenSubKey(valueName) != null) { RDPICApath = rkTest.OpenSubKey(valueName).ToString(); }
Console.WriteLine("Getting CurrentUser ICA-RDP path from string = " + RDPICApath);
//List<string> RDPICAnumber = RDPICApath.Split('\\').ToList();
string RDPICAnumber = RDPICApath.Substring(RDPICApath.LastIndexOf('\\') + 1);
Console.WriteLine("Current User RDPICAnumber = " + RDPICAnumber);
//Getting reg local machine info for Citrix based on RDP/Citrix session ID "RDPICAnumber"
string regLocal = @"SOFTWARE\Citrix\Ica\Session\" + RDPICAnumber + @"\Connection";
RegistryKey localKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
RegistryKey citrixKey = localKey.OpenSubKey(regLocal);
Console.WriteLine("Registry " + citrixKey + " Does Exist - going to get ClientType");
//getting clietAddress var from citrixKey
string clientType = "";
if (citrixKey != null && citrixKey.GetValue("clientType") != null)
{clientType = citrixKey.GetValue("ClientType").ToString();}
Console.WriteLine("Getting current user clientType from string = " + clientType);
}
rkTest.Close();
rkCurrentUser.Close();
Console.ReadLine();
}
}
}
您可以轻松地将 clientType 替换为 ClientProductID 并使用以下参考获取 ClientProductID information.
【讨论】:
foreach (DictionaryEntry de in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process)) { string log = "\r\n" + de.Key + "=" + de.Value; Console.WriteLine(" {0} = {1}", de.Key, de.Value); }
我也面临同样的问题。我尝试从 WTSQuerySessionInformation Win32 API 函数中读取 WTSClientProductId 值,但它始终返回 0x0001,即使从 Android 平板电脑启动的会话中调用也是如此。
【讨论】: