[C #] Getting internal computer information-Computerinfohelper

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.