C# 如果Windows服务器上安装了远程桌面服务(RDS)/远程桌面会话主机(RDSH),请咨询.NET
我需要使用.NET检测远程桌面会话主机是否安装在windows 2008-2019中,作为我们产品的先决条件检查程序的一部分。无法在RDS服务器上以执行模式安装某些部件,因此我必须告诉用户,他必须切换到安装模式…从Windows Server 2008开始,您可以使用以下类型的代码检查是否安装了RDS角色:C# 如果Windows服务器上安装了远程桌面服务(RDS)/远程桌面会话主机(RDSH),请咨询.NET,c#,.net,vb.net,terminal,rds,C#,.net,Vb.net,Terminal,Rds,我需要使用.NET检测远程桌面会话主机是否安装在windows 2008-2019中,作为我们产品的先决条件检查程序的一部分。无法在RDS服务器上以执行模式安装某些部件,因此我必须告诉用户,他必须切换到安装模式…从Windows Server 2008开始,您可以使用以下类型的代码检查是否安装了RDS角色: static void Main(string[] args) { // 14 is the identifier of the Remote Desktop Services ro
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;
}
参考资料:您是否还知道,如果安装了Windows server 2008或更高版本的RDS角色,则如何使用.NET检查该角色是否处于安装或执行模式?