Get internal information about your computer-Computerinfohelper, code
ComputerInfoHelper.cs
/// <summary> ///Computer Information Helper class/// </summary> Public classComputerinfohelper {/// <summary> ///Get disk capacity Rollup/// </summary> Public Static Longgettotaldisksize () {Try { varDiskdrivemanagement =NewManagementClass (wmipath.diskdrive); varDiskdrivemanagementinstances =diskdrivemanagement.getinstances (); returnDiskdrivemanagementinstances.oftype<managementobject>() . Select (ManagementObject=Convert.toint64 (Managementobject[managementbaseobjectpropertyname.size])). Aggregate<Long,Long> (0, (current, disksize) = DiskSize +Current ); } Catch(Exception e) {Console.WriteLine (e); Throw; } } }
ManagementBaseObjectPropertyName.cs
namespacewen.helpers.common.computer.config{ Public classManagementbaseobjectpropertyname {/// <summary> ///name/// </summary> Public Const stringName ="Name"; /// <summary> ///Graphics Chip/// </summary> Public Const stringVideoprocessor ="Videoprocessor"; /// <summary> ///Memory Size/// </summary> Public Const stringAdapterRAM ="AdapterRAM"; /// <summary> ///Wide Resolution/// </summary> Public Const stringScreenWidth ="ScreenWidth"; /// <summary> ///High Resolution/// </summary> Public Const stringScreenHeight ="ScreenHeight"; /// <summary> ///Computer Model/// </summary> Public Const stringVersion ="Version"; /// <summary> ///HDD Capacity/// </summary> Public Const stringSize ="Size"; /// <summary> ///Memory Capacity/// </summary> Public Const stringCapacity ="capacity"; /// <summary> ///number of CPU cores/// </summary> Public Const stringNumberOfCores ="NumberOfCores"; }}
WmiPath.cs
namespacewen.helpers.common.computer.config{ Public classWmipath {/// <summary> ///Memory/// </summary> Public Const stringPhysicalMemory ="win32_physicalmemory"; /// <summary> ///CPU/// </summary> Public Const stringProcessor ="Win32_Processor"; /// <summary> ///HDD/// </summary> Public Const stringDiskDrive ="win32_diskdrive"; /// <summary> ///Computer Model/// </summary> Public Const stringComputersystemproduct ="win32_computersystemproduct"; /// <summary> ///resolution/// </summary> Public Const stringDesktopmonitor ="Win32_DesktopMonitor"; /// <summary> ///video card/// </summary> Public Const stringVideocontroller ="Win32_VideoController"; /// <summary> ///Operating System/// </summary> Public Const stringOperatingSystem ="Win32_OperatingSystem"; }}
Second, the test
1. Computer hard Drive information
2. Hard drive information in My Computer
3. Test code
4. Output Result:
All hard disk and USB stick and memory card, because the manufacturer's calculation method and operating system calculation method is not the same, the former according to 1MB = 1000KB calculation, the latter by 1MB = 1024KB calculation, so, the actual capacity in the computer can be seen with the factory brand name capacity has a certain difference, the law is 1G = 0.9 3G (approximately equals), such as 100G, the actual 100G * 0.93 = 93G, the specific capacity can be referred to this formula calculation.
[C #] Getting internal computer information-Computerinfohelper