尝试检查其他工作站的友好操作系统名称

时间:2018-10-31 21:58:36

标签: c# operating-system

我试图找到与我的工作站不同的工作站的友好操作系统名称。这是我使用时发生的:

var name = (from x in new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem").Get().Cast<ManagementObject>()
                        select x.GetPropertyValue("Caption")).FirstOrDefault();

它返回我工作站的OS名称。您能建议我找到一种更好的方法吗?

提前谢谢!

1 个答案:

答案 0 :(得分:1)

您可以使用System.DirectoryServices在目录“ WinNT”上进行搜索,您可以在此处了解更多信息:

https://docs.microsoft.com/en-us/dotnet/api/system.directoryservices.directoryentry.path?view=netframework-4.7.2

示例解决方案-将名称添加到列表

// create list to add the names to
var pcnames = new List<string>();
// establish the domains in the local network
var directory = new DirectoryEntry("WinNT:");
// iterate through the children
foreach (DirectoryEntry workstation in directory.Children)
{
  pcnames.Add(workstation.Name)
}