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;
        }
Exemple #2
0
        /// <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;
        }
Exemple #3
0
 /// <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);
 }