【问题标题】:Check with .NET if Remote Desktop Services (RDS) / Remote Desktop Session Host (RDSH) is installed on a Windows Server使用 .NET 检查远程桌面服务 (RDS)/远程桌面会话主机 (RDSH) 是否安装在 Windows 服务器上
【发布时间】:2019-02-07 09:05:33
【问题描述】:

我需要使用 .NET 检测远程桌面会话主机是否安装在 Windows 2008 - 2019 中,作为我们产品的先决条件检查器的一部分。在 RDS 服务器上无法以执行模式安装某些部件,所以我必须告诉用户,他必须更改为安装模式...

【问题讨论】:

    标签: c# .net vb.net terminal rds


    【解决方案1】:

    从 Windows Server 2008 起,您可以使用以下类型的代码检查是否安装了 RDS 角色:

    static void Main(string[] args)
    {
        // 14 is the identifier of the Remote Desktop Services role.
        HasServerFeatureById(14);
    }
    
    static bool HasServerFeatureById(UInt32 roleId)
    {
        try
        {
            ManagementClass serviceClass = new ManagementClass("Win32_ServerFeature");
            foreach (ManagementObject feature in serviceClass.GetInstances())
            {
                if ((UInt32)feature["ID"] == roleId)
                {
                    return true;
                }
            }
    
            return false;
        }
        catch (ManagementException)
        {
            // The most likely cause of this is that this is being called from an 
            // operating system that is not a server operating system.
        }
    
        return false;
    }
    

    参考:Detecting Whether the Remote Desktop Services Role Is Installed

    【讨论】:

    • 您是否也知道,如何通过.NET检查,安装了具有RDS角色的Windows server 2008或更高版本是处于安装模式还是执行模式?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-17
    • 1970-01-01
    • 1970-01-01
    • 2015-04-12
    • 2020-08-18
    • 2013-05-06
    • 1970-01-01
    相关资源
    最近更新 更多