如何确定" Active Directory域服务]角色已在服务器上安装 [英] How to determine if the "Active Directory Domain Services" role has been installed on a server
问题描述
我试图找出如果Active Directory域服务安装一个Windows服务器。
I am trying to figure out if the Active Directory Domain Services are installed a windows server.
我知道他们在Server Manager中显示出来,但我可以通过编程如果角色在服务器上使用C#代码
I know they show up in the Server Manager, but can I programmatically get if the role is installed on a server using C# code
推荐答案
安装得到,如果你知道你要测试的服务器的名称,可以远程运行具有域管理员权限的程序,你可以使用WMI:
If you know the name of the server you want to test and can run the program with domain admin privileges remotely, you can use WMI:
internal static bool IsDomainController(string ServerName)
{
StringBuilder Results = new StringBuilder();
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("\\\\" + ServerName + "\\root\\CIMV2",
"SELECT * FROM Win32_ServerFeature WHERE ID = 10");
foreach (ManagementObject queryObj in searcher.Get())
{
Results.AppendLine(queryObj.GetPropertyValue("ID").ToString());
}
}
catch (ManagementException)
{
//handle exception
}
if (Results.Length > 0)
return true;
else
return false;
}
如果你正在运行在本地服务器上的WMI路径改变为
If you're running that locally on the server, the WMI path changes to:
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_ServerFeature WHERE ID = 10");
见的上Win32_ServerFeature 的角色及其ID号的完整列表MSDN参考。
See the MSDN reference on Win32_ServerFeature for a full list of roles and their ID numbers.
这篇关于如何确定" Active Directory域服务]角色已在服务器上安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!