本文整理匯總了C#中System.Management.ManagementClass.Select方法的典型用法代碼示例。如果您正苦於以下問題:C# ManagementClass.Select方法的具體用法?C# ManagementClass.Select怎麽用?C# ManagementClass.Select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Management.ManagementClass
的用法示例。
在下文中一共展示了ManagementClass.Select方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetMachines
public IEnumerable<IHyperVMachine> GetMachines()
{
var en = new ManagementClass(_scope, new ManagementPath("Msvm_ComputerSystem"), null)
.GetInstances()
.OfType<ManagementObject>().Where(x => "Virtual Machine" == (string)x["Caption"]);
List<HyperVMachine> machines = en.Select(machine => new HyperVMachine(machine)).ToList();
return machines;
}
示例2: GetSystemInfo
/// <summary>
/// 獲取係統信息
/// </summary>
public static SystemInfo GetSystemInfo()
{
SystemInfo info = new SystemInfo();
//CPU
var objects = new ManagementClass(WMIPath.Win32_Processor.ToString()).GetInstances().Cast<ManagementObject>().ToArray();
info.CpuName = objects.Select(m => (string)m.Properties["Name"].Value).FirstOrDefault();
info.CpuId = objects.Select(m => (string)m.Properties["ProcessorId"].Value).FirstOrDefault();
//主板
objects = new ManagementClass(WMIPath.Win32_BaseBoard.ToString()).GetInstances().Cast<ManagementObject>().ToArray();
info.BoardName = objects.Select(m => (string)m.Properties["Manufacturer"].Value + " " +
(string)m.Properties["Product"].Value + " " +
(string)m.Properties["Version"].Value).FirstOrDefault();
info.BoardId = objects.Select(m => (string)m.Properties["SerialNumber"].Value).FirstOrDefault();
//硬盤
objects = new ManagementClass(WMIPath.Win32_DiskDrive.ToString()).GetInstances().Cast<ManagementObject>().ToArray();
info.DiskName = objects.Select(m => (string)m.Properties["Model"].Value + " " +
(Convert.ToDouble(m.Properties["Size"].Value) / (1024 * 1024 * 1024)) + " GB").FirstOrDefault();
info.DiskId = objects.Select(m => (string)m.Properties["SerialNumber"].Value).FirstOrDefault();
//操作係統
objects = new ManagementClass(WMIPath.Win32_OperatingSystem.ToString()).GetInstances().Cast<ManagementObject>().ToArray();
info.OSName = objects.Select(m => (string)m.Properties["Caption"].Value).FirstOrDefault();
info.OSCsdVersion = objects.Select(m => (string)m.Properties["CSDVersion"].Value).FirstOrDefault();
info.OSIs64Bit = objects.Select(m => (string)m.Properties["OSArchitecture"].Value == "64-bit").FirstOrDefault();
info.OSVersion = objects.Select(m => (string)m.Properties["Version"].Value).FirstOrDefault();
info.OSPath = objects.Select(m => (string)m.Properties["WindowsDirectory"].Value).FirstOrDefault();
//內存
info.PhysicalMemoryFree = objects.Select(m => Convert.ToDouble(m.Properties["FreePhysicalMemory"].Value) / (1024)).FirstOrDefault();
info.PhysicalMemoryTotal = objects.Select(m => Convert.ToDouble(m.Properties["TotalVisibleMemorySize"].Value) / (1024)).FirstOrDefault();
//屏幕
objects = new ManagementClass(WMIPath.Win32_VideoController.ToString()).GetInstances().Cast<ManagementObject>().ToArray();
info.ScreenWith = objects.Select(m => Convert.ToInt32(m.Properties["CurrentHorizontalResolution"].Value)).FirstOrDefault();
info.ScreenHeight = objects.Select(m => Convert.ToInt32(m.Properties["CurrentVerticalResolution"].Value)).FirstOrDefault();
info.ScreenColorDepth = objects.Select(m => Convert.ToInt32(m.Properties["CurrentBitsPerPixel"].Value)).FirstOrDefault();
return info;
}
示例3: GetProcessNames
/// <summary>
/// 獲取當前係統運行的進程列表
/// </summary>
public static IEnumerable<string> GetProcessNames()
{
var objects = new ManagementClass(WMIPath.Win32_Process.ToString()).GetInstances().Cast<ManagementObject>().ToArray();
return objects.Select(m => (string)m.Properties["Caption"].Value).OrderBy(m => m);
}