当前位置: 首页>>代码示例>>C#>>正文


C# ManagementClass.Select方法代码示例

本文整理汇总了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;
        }
开发者ID:AlexsJones,项目名称:HyperVRemote,代码行数:10,代码来源:HyperVProvider.cs

示例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;
        }
开发者ID:BiaoLiu,项目名称:osharp,代码行数:43,代码来源:SystemInfoHandler.cs

示例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);
 }
开发者ID:BiaoLiu,项目名称:osharp,代码行数:8,代码来源:SystemInfoHandler.cs


注:本文中的System.Management.ManagementClass.Select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。