【发布时间】:2019-02-07 09:05:33
【问题描述】:
我需要使用 .NET 检测远程桌面会话主机是否安装在 Windows 2008 - 2019 中,作为我们产品的先决条件检查器的一部分。在 RDS 服务器上无法以执行模式安装某些部件,所以我必须告诉用户,他必须更改为安装模式...
【问题讨论】:
标签: c# .net vb.net terminal rds
我需要使用 .NET 检测远程桌面会话主机是否安装在 Windows 2008 - 2019 中,作为我们产品的先决条件检查器的一部分。在 RDS 服务器上无法以执行模式安装某些部件,所以我必须告诉用户,他必须更改为安装模式...
【问题讨论】:
标签: c# .net vb.net terminal rds
从 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
【讨论】: