软装设计公司网站,wordpress根据点击量最高查询文章,外贸都有哪些平台,网络购物系统需求分析通过WMI类来获取电脑各种信息#xff0c;参考文章#xff1a;WMI_04_常见的WMI类的属性_wmi scsilogicalunit_fantongl的博客-CSDN博客
自己整理了获取电脑CPU、内存、屏幕、磁盘等信息的代码 #region 系统信息/// summary/// 电脑信息/// /summarypublic p…通过WMI类来获取电脑各种信息参考文章WMI_04_常见的WMI类的属性_wmi scsilogicalunit_fantongl的博客-CSDN博客
自己整理了获取电脑CPU、内存、屏幕、磁盘等信息的代码 #region 系统信息/// summary/// 电脑信息/// /summarypublic partial class ComputerInfo{/// summary/// 系统版本/// para示例Windows 10 Enterprise/para/// /summarypublic static string OSProductName { get; } (string)Registry.GetValue(HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion, ProductName, 0);/// summary/// 操作系统版本/// para示例Microsoft Windows 10.0.18363/para/// /summarypublic static string OSDescription { get; } System.Runtime.InteropServices.RuntimeInformation.OSDescription;/// summary/// 操作系统架构see crefArchitecture/// para示例X64/para/// /summarypublic static string OSArchitecture { get; } System.Runtime.InteropServices.RuntimeInformation.OSArchitecture.ToString();/// summary/// 获取系统信息/// /summary/// returns/returnspublic static SystemInfo GetSystemInfo(){SystemInfo systemInfo new SystemInfo();var osProductName OSProductName.Trim().Replace( , _);var osVersionNames Enum.GetNames(typeof(OSVersion)).ToList();for (int i 0; i osVersionNames.Count; i){var osVersionName osVersionNames[i];if (osProductName.Contains(osVersionName)){systemInfo.OSVersion (OSVersion)Enum.Parse(typeof(OSVersion), osVersionName);systemInfo.WindowsVersion osProductName.Replace(osVersionName, ).Replace(_, );}}systemInfo.WindowsVersionNo OSDescription;systemInfo.Architecture OSArchitecture;return systemInfo;}}/// summary/// 系统信息/// /summarypublic class SystemInfo{/// summary/// 系统版本。如:Windows 10/// /summarypublic string WindowsVersion { get; set; }/// summary/// 系统版本。如专业版/// /summarypublic OSVersion OSVersion { get; set; }/// summary/// Windows版本号。如Microsoft Windows 10.0.18363/// /summarypublic string WindowsVersionNo { get; set; }/// summary/// 操作系统架构。如X64/// /summarypublic string Architecture { get; set; }}/// summary/// 系统客户版本/// /summarypublic enum OSVersion{/// summary/// 家庭版/// /summaryHome,/// summary/// 专业版以家庭版为基础/// /summaryPro,Professional,/// summary/// 企业版以专业版为基础/// /summaryEnterprise,/// summary/// 教育版以企业版为基础/// /summaryEducation,/// summary/// 移动版/// /summaryMobile,/// summary/// 企业移动版以移动版为基础/// /summaryMobile_Enterprise,/// summary/// 物联网版/// /summaryIoT_Core,/// summary/// 专业工作站版以专业版为基础/// /summaryPro_for_Workstations}#endregion#region CPU信息public partial class ComputerInfo{/// summary/// CPU信息/// /summary/// returns/returnspublic static CPUInfo GetCPUInfo(){var cpuInfo new CPUInfo();var cpuInfoType cpuInfo.GetType();var cpuInfoFields cpuInfoType.GetProperties().ToList();var moc new ManagementClass(Win32_Processor).GetInstances();foreach (var mo in moc){foreach (var item in mo.Properties){if (cpuInfoFields.Exists(f f.Name item.Name)){var p cpuInfoType.GetProperty(item.Name);p.SetValue(cpuInfo, item.Value);}}}return cpuInfo;}}/// summary/// CPU信息/// /summarypublic class CPUInfo{/// summary/// 操作系统类型32或64/// /summarypublic uint AddressWidth { get; set; }/// summary/// 处理器的名称。如Intel(R) Core(TM) i3-8100 CPU 3.60GHz/// /summarypublic string Name { get; set; }/// summary/// 处理器的当前实例的数目。如4。4核/// /summarypublic uint NumberOfEnabledCore { get; set; }/// summary/// 用于处理器的当前实例逻辑处理器的数量。如4。4线程/// /summarypublic uint NumberOfLogicalProcessors { get; set; }/// summary/// 系统的名称。计算机名称。如GREAMBWANG/// /summarypublic string SystemName { get; set; }}#endregion#region 内存信息public partial class ComputerInfo{/// summary/// 内存信息/// /summary/// returns/returnspublic static RAMInfo GetRAMInfo(){var ramInfo new RAMInfo();var totalPhysicalMemory TotalPhysicalMemory;var memoryAvailable MemoryAvailable;var conversionValue 1024.0 * 1024.0 * 1024.0;ramInfo.TotalPhysicalMemoryGBytes Math.Round((double)(totalPhysicalMemory / conversionValue), 1);ramInfo.MemoryAvailableGBytes Math.Round((double)(memoryAvailable / conversionValue), 1);ramInfo.UsedMemoryGBytes Math.Round((double)((totalPhysicalMemory - memoryAvailable) / conversionValue), 1);ramInfo.UsedMemoryRatio (int)(((totalPhysicalMemory - memoryAvailable) * 100.0) / totalPhysicalMemory);return ramInfo;}/// summary/// 总物理内存B/// /summary/// returns/returnspublic static long TotalPhysicalMemory{get{long totalPhysicalMemory 0;ManagementClass mc new ManagementClass(Win32_ComputerSystem);ManagementObjectCollection moc mc.GetInstances();foreach (ManagementObject mo in moc){if (mo[TotalPhysicalMemory] ! null){totalPhysicalMemory long.Parse(mo[TotalPhysicalMemory].ToString());}}return totalPhysicalMemory;}}/// summary/// 获取可用内存B/// /summarypublic static long MemoryAvailable{get{long availablebytes 0;ManagementClass mos new ManagementClass(Win32_OperatingSystem);foreach (ManagementObject mo in mos.GetInstances()){if (mo[FreePhysicalMemory] ! null){availablebytes 1024 * long.Parse(mo[FreePhysicalMemory].ToString());}}return availablebytes;}}}/// summary/// 内存信息/// /summarypublic class RAMInfo{/// summary/// 总物理内存GB/// /summarypublic double TotalPhysicalMemoryGBytes { get; set; }/// summary/// 获取可用内存GB/// /summarypublic double MemoryAvailableGBytes { get; set; }/// summary/// 获取已用内存GB/// /summarypublic double UsedMemoryGBytes { get; set; }/// summary/// 内存使用率/// /summarypublic int UsedMemoryRatio { get; set; }}#endregion#region 屏幕信息public partial class ComputerInfo{/// summary/// 屏幕信息/// /summarypublic static GPUInfo GetGPUInfo(){GPUInfo gPUInfo new GPUInfo();gPUInfo.CurrentResolution MonitorHelper.GetResolution();gPUInfo.MaxScreenResolution GetGPUInfo2();return gPUInfo;}/// summary/// 获取最大分辨率/// /summary/// returns/returnsprivate static Size GetMaximumScreenSizePrimary(){var scope new System.Management.ManagementScope();var q new System.Management.ObjectQuery(SELECT * FROM CIM_VideoControllerResolution);UInt32 maxHResolution 0;UInt32 maxVResolution 0;using (var searcher new System.Management.ManagementObjectSearcher(scope, q)){var results searcher.Get();foreach (var item in results){if ((UInt32)item[HorizontalResolution] maxHResolution)maxHResolution (UInt32)item[HorizontalResolution];if ((UInt32)item[VerticalResolution] maxVResolution)maxVResolution (UInt32)item[VerticalResolution];}}return new Size((int)maxHResolution, (int)maxVResolution);}/// summary/// 获取最大分辨率2/// CurrentHorizontalResolution:1920/// CurrentVerticalResolution:1080/// /summary/// returns/returnspublic static Size GetGPUInfo2(){var gpu new StringBuilder();var moc new ManagementObjectSearcher(select * from Win32_VideoController).Get();var currentHorizontalResolution 0;var currentVerticalResolution 0;foreach (var mo in moc){foreach (var item in mo.Properties){if (item.Name CurrentHorizontalResolution item.Value ! null)currentHorizontalResolution int.Parse((item.Value.ToString()));if (item.Name CurrentVerticalResolution item.Value ! null)currentVerticalResolution int.Parse((item.Value.ToString()));//gpu.Append(${item.Name}:{item.Value}\r\n);}}//var res gpu.ToString();//return res;return new Size(currentHorizontalResolution, currentVerticalResolution);}}public class MonitorHelper{/// summary/// 获取DC句柄/// /summary[DllImport(user32.dll)]static extern IntPtr GetDC(IntPtr hdc);/// summary/// 释放DC句柄/// /summary[DllImport(user32.dll, EntryPoint ReleaseDC)]static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hdc);/// summary/// 获取句柄指定的数据/// /summary[DllImport(gdi32.dll)]static extern int GetDeviceCaps(IntPtr hdc, int nIndex);/// summary/// 获取设置的分辨率修改缩放该值不改变/// {Width 1920 Height 1080}/// /summary/// returns/returnspublic static Size GetResolution(){Size size new Size();IntPtr hdc GetDC(IntPtr.Zero);size.Width GetDeviceCaps(hdc, DeviceCapsType.DESKTOPHORZRES);size.Height GetDeviceCaps(hdc, DeviceCapsType.DESKTOPVERTRES);ReleaseDC(IntPtr.Zero, hdc);return size;}/// summary/// 获取屏幕物理尺寸(mm,mm)/// {Width 476 Height 268}/// /summary/// returns/returnspublic static Size GetScreenSize(){Size size new Size();IntPtr hdc GetDC(IntPtr.Zero);size.Width GetDeviceCaps(hdc, DeviceCapsType.HORZSIZE);size.Height GetDeviceCaps(hdc, DeviceCapsType.VERTSIZE);ReleaseDC(IntPtr.Zero, hdc);return size;}/// summary/// 获取屏幕的尺寸---inch/// 21.5/// /summary/// returns/returnspublic static float GetScreenInch(){Size size GetScreenSize();double inch Math.Round(Math.Sqrt(Math.Pow(size.Width, 2) Math.Pow(size.Height, 2)) / 25.4, 1);return (float)inch;}}/// summary/// GetDeviceCaps 的 nidex值/// /summarypublic class DeviceCapsType{public const int DRIVERVERSION 0;public const int TECHNOLOGY 2;public const int HORZSIZE 4;//以毫米为单位的显示宽度public const int VERTSIZE 6;//以毫米为单位的显示高度public const int HORZRES 8;public const int VERTRES 10;public const int BITSPIXEL 12;public const int PLANES 14;public const int NUMBRUSHES 16;public const int NUMPENS 18;public const int NUMMARKERS 20;public const int NUMFONTS 22;public const int NUMCOLORS 24;public const int PDEVICESIZE 26;public const int CURVECAPS 28;public const int LINECAPS 30;public const int POLYGONALCAPS 32;public const int TEXTCAPS 34;public const int CLIPCAPS 36;public const int RASTERCAPS 38;public const int ASPECTX 40;public const int ASPECTY 42;public const int ASPECTXY 44;public const int SHADEBLENDCAPS 45;public const int LOGPIXELSX 88;//像素/逻辑英寸水平public const int LOGPIXELSY 90; //像素/逻辑英寸垂直public const int SIZEPALETTE 104;public const int NUMRESERVED 106;public const int COLORRES 108;public const int PHYSICALWIDTH 110;public const int PHYSICALHEIGHT 111;public const int PHYSICALOFFSETX 112;public const int PHYSICALOFFSETY 113;public const int SCALINGFACTORX 114;public const int SCALINGFACTORY 115;public const int VREFRESH 116;public const int DESKTOPVERTRES 117;//垂直分辨率public const int DESKTOPHORZRES 118;//水平分辨率public const int BLTALIGNMENT 119;}/// summary/// 屏幕信息/// /summarypublic class GPUInfo{/// summary/// 当前分辨率/// /summarypublic Size CurrentResolution { get; set; }/// summary/// 最大分辨率/// /summarypublic Size MaxScreenResolution { get; set; }}#endregion#region 硬盘信息public partial class ComputerInfo{/// summary/// 磁盘信息/// /summarypublic static ListDiskInfo GetDiskInfo(){ListDiskInfo diskInfos new ListDiskInfo();try{var moc new ManagementClass(Win32_LogicalDisk).GetInstances();foreach (ManagementObject mo in moc){var diskInfo new DiskInfo();var diskInfoType diskInfo.GetType();var diskInfoFields diskInfoType.GetProperties().ToList();foreach (var item in mo.Properties){if (diskInfoFields.Exists(f f.Name item.Name)){var p diskInfoType.GetProperty(item.Name);p.SetValue(diskInfo, item.Value);}}diskInfos.Add(diskInfo);}//B转GBfor (int i 0; i diskInfos.Count; i){diskInfos[i].Size Math.Round((double)(diskInfos[i].Size / 1024.0 / 1024.0 / 1024.0), 1);diskInfos[i].FreeSpace Math.Round((double)(diskInfos[i].FreeSpace / 1024.0 / 1024.0 / 1024.0), 1);}}catch (Exception ex){}return diskInfos;}}/// summary/// 磁盘信息/// /summarypublic class DiskInfo{/// summary/// 磁盘ID 如D:/// /summarypublic string DeviceID { get; set; }/// summary/// 驱动器类型。3为本地固定磁盘2为可移动磁盘/// /summarypublic uint DriveType { get; set; }/// summary/// 磁盘名称。如系统/// /summarypublic string VolumeName { get; set; }/// summary/// 描述。如本地固定磁盘/// /summarypublic string Description { get; set; }/// summary/// 文件系统。如NTFS/// /summarypublic string FileSystem { get; set; }/// summary/// 磁盘容量GB/// /summarypublic double Size { get; set; }/// summary/// 可用空间GB/// /summarypublic double FreeSpace { get; set; }public override string ToString(){return ${VolumeName}({DeviceID}), {FreeSpace}GB is available for {Size}GB in total, {FileSystem}, {Description};}}#endregion
可以获取下面这些信息 ComputerCheck Info: System Info:Windows 10 Enterprise, Enterprise, X64, Microsoft Windows 10.0.18363 CPU Info:Intel(R) Core(TM) i3-8100 CPU 3.60GHz, 4 Core 4 Threads RAM Info:12/15.8GB(75%) GPU Info:1920*1080 / 1920*1080 Disk Info:系统(C:), 74.2GB is available for 238.1GB in total, NTFS, 本地固定磁盘 软件(D:), 151.9GB is available for 300GB in total, NTFS, 本地固定磁盘 办公(E:), 30.7GB is available for 300GB in total, NTFS, 本地固定磁盘 其它(F:), 256.3GB is available for 331.5GB in total, NTFS, 本地固定磁盘 参考文章
WMI_04_常见的WMI类的属性_wmi scsilogicalunit_fantongl的博客-CSDN博客
C#获取计算机物理内存和可用内存大小封装类SystemInfo_c# 获得物理内存大小_CodingPioneer的博客-CSDN博客
https://www.cnblogs.com/pilgrim/p/15115925.html
win10各种版本英文名称是什么 - 编程之家
https://www.cnblogs.com/dongweian/p/14182576.html
C# 使用WMI获取所有服务的信息_c# wmi_FireFrame的博客-CSDN博客
WMI_02_常用WMI查询列表_fantongl的博客-CSDN博客