【问题标题】:C# Remote Desktop: Want to know the Client Device or Client Operating SystemC# 远程桌面:想知道客户端设备或客户端操作系统
【发布时间】:2017-05-24 14:40:34
【问题描述】:

我的应用程序通过 RDP 在 Windows 服务器上运行。在应用程序中,我想知道客户端(带有 RDP 会话)是否是移动设备。

是否可以获取客户端操作系统?

【问题讨论】:

    标签: c# windows mobile rdp


    【解决方案1】:

    有关当前用户连接的所有 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.

    【讨论】:

    • 谢谢,但我使用的是 Windows Server 2016,而不是 Citrix Server。
    • 你好。有关当前用户连接的所有 RDP 环境变量的列表,请参阅以下命令。如果查找操作系统类型或连接设备,请关注操作系统和客户端名称,但建议在移动/Windows RDP 连接之间检查打印输出中的任何差异。 foreach (DictionaryEntry de in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process)) { string log = "\r\n" + de.Key + "=" + de.Value; Console.WriteLine(" {0} = {1}", de.Key, de.Value); }
    • 您好,我检查了所有环境变量。但我总是从 WindowsServer 会话中获取信息,而不是从真实客户端获取信息。 OS=Windows_NT CLIENTNAME 对我不起作用。
    • 所以 CLIENTNAME 从移动设备连接时不返回任何值?这是不幸的。这些是 Windows RDP 会话提供的最有用的变量。您是否考虑过使用客户端访问许可证 (CAL)?可以为每个设备分配它们以进行跟踪。 docs.microsoft.com/en-us/windows-server/remote/…
    • 嗨,H.v.H,我在 AWS 中创建了一个测试环境,以尝试进一步提供帮助并抑制好奇心。我刚刚在从三星移动设备到 WS16 的 RDP 会话中运行了上述 EnvironmentVariableTarget.Process.exe,它返回了一个 CLIENTNAME 变量“SM-N920P-7.0”。您必须以 RDP 会话中的用户身份运行上述内容。当我用谷歌搜索“SM-N920P-7.0”时,它会返回正确的移动设备型号。希望这会有所帮助。
    【解决方案2】:

    我也面临同样的问题。我尝试从 WTSQuerySessionInformation Win32 API 函数中读取 WTSClientProductId 值,但它始终返回 0x0001,即使从 Android 平板电脑启动的会话中调用也是如此。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      • 2013-04-26
      • 1970-01-01
      相关资源
      最近更新 更多