本文整理汇总了C#中System.Management.ManagementObjectSearcher.GetRelated方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementObjectSearcher.GetRelated方法的具体用法?C# ManagementObjectSearcher.GetRelated怎么用?C# ManagementObjectSearcher.GetRelated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.ManagementObjectSearcher
的用法示例。
在下文中一共展示了ManagementObjectSearcher.GetRelated方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMountPoints
internal static string[] GetMountPoints(string VHD)
{
if (VHD == null)
return null;
List<string> ret = new List<string>();
var image = new ManagementObjectSearcher(Utility.GetScope(),
new SelectQuery(Utility.DiskStrings.MountedStorage)).Get()
.Cast<ManagementObject>()
.FirstOrDefault(Obj => (Obj["Name"].ToString()
.Equals(VHD, StringComparison.InvariantCultureIgnoreCase)));
if (image == null)
return new string[0];
var baseScope = new ManagementScope(@"root\cimv2");
baseScope.Connect();
var disk = new ManagementObjectSearcher(baseScope,
new SelectQuery(Utility.DiskStrings.DiskDrive,
"SCSILogicalUnit=" + image["Lun"] +
" and SCSIPort=" + image["PortNumber"] +
" and SCSITargetID=" + image["TargetID"]))
.Get().Cast<ManagementObject>().FirstOrDefault();
var parts = disk.GetRelated(Utility.DiskStrings.DiskPartition);
foreach (var drives in from ManagementObject part in parts select part.GetRelated(Utility.DiskStrings.LogicalDisk))
{
ret.AddRange(from ManagementObject drive in drives select (drive["DeviceID"].ToString()[email protected]"\"));
}
return ret.ToArray();
}