C # read hard disk information ManagementClass class

Source: Internet
Author: User

One, in many cases, you may need to get the hardware information of the microcomputer. This sentence needs to be added as follows:

using System.Management;

To obtain hardware information, you need to know the hardware parameter information:

Win32_Processor,//CPU ProcessorWin32_physicalmemory,//Physical Memory StripsWin32_Keyboard,//keyboardWin32_pointingdevice,//point input device, including mouse. win32_floppydrive,//Floppy DriveWin32_DiskDrive,//Hard Drivewin32_cdromdrive,//Optical DriveWin32_baseboard,//MotherboardWin32_BIOS,//BIOS ChipWin32_ParallelPort,//and the PortWin32_serialport,//Serial PortWin32_serialportconfiguration,//Serial ConfigurationWin32_sounddevice,//multimedia settings, commonly referred to as sound cards. Win32_systemslot,//motherboard Slots (ISA & PCI & AGP)Win32_usbcontroller,//USB ControllerWin32_NetworkAdapter,//Network AdapterWin32_NetworkAdapterConfiguration,//Network Adapter SettingsWin32_Printer,//PrinterWin32_PrinterConfiguration,//Printer SettingsWin32_PrintJob,//Printer TasksWin32_tcpipprinterport,//Printer PortWin32_potsmodem,//MODEMWin32_potsmodemtoserialport,//MODEM PortWin32_DesktopMonitor,//DisplayWin32_displayconfiguration,//video cardWin32_displaycontrollerconfiguration,//Graphics SettingsWin32_VideoController,//graphics details. Win32_videosettings,//display mode supported by the graphics card. //Operating SystemWin32_TimeZone,//Time ZoneWin32_SystemDriver,//Driver ProgramWin32_DiskPartition,//Disk PartitioningWin32_LogicalDisk,//Logical DiskWin32_logicaldisktopartition,//The partition where the logical disk resides and its location. Win32_LogicalMemoryConfiguration,//Logical Memory ConfigurationWin32_PageFile,//System page File informationWin32_PageFileSetting,//page File SettingsWin32_bootconfiguration,//System Boot ConfigurationWin32_ComputerSystem,//Computer Information BriefWin32_OperatingSystem,//Operating System InformationWin32_startupcommand,//System Auto-Start programWin32_Service,//System-Installed servicesWin32_Group,//System Management GroupWin32_groupuser,//System Group AccountWin32_UserAccount,//User AccountWin32_Process,//System ProcessesWin32_thread,//System ThreadsWin32_Share,//sharedWin32_NetworkClient,//Installed network ClientsWin32_NetworkProtocol,//Installed network Protocols
View Code

According to the information provided above, get what you need;

New ManagementClass ("win32_processor");  

The following describes the ManagementClass class;

1.GetInstances (): There are four overloads of this method;

2.Get (): There are two overloads for this method;

3.GetSubclasses (): There are four overloaded versions of this method

Two. Some applications of the ManagementClass class:

1. Get the CPU number

       /// <summary>        ///Get CPU Number/// </summary>        /// <returns></returns>         Public stringGetcpuid () {varCPUID =string.            Empty; varMC =NewManagementClass ("Win32_Processor"); varMOC =MC.            GetInstances (); foreach(varOinchMOC) {                varMo =(ManagementObject) o; CPUID= mo. properties["Processorid"].            Value.tostring (); }            returnCpuid; }
View Code

2. Get the hard drive serial number

1 /// <summary>2         ///get the hard drive serial number3         /// </summary>4         /// <returns></returns>5          Public stringGetdiskserialnumber ()6         {7             //This mode may have different results after inserting a USB flash drive, such as when inserting my phone8             varHDid =string. Empty;9             varMC =NewManagementClass ("win32_diskdrive");Ten             varMOC =MC. GetInstances (); One             foreach(varOinchMOC) A             { -                 varMo =(ManagementObject) o; -HDid = (string) mo. properties["Model"]. Value; the                 //This statement solves the problem of having multiple physical disks, taking only the first physical hard disk -                  Break; -             } -             returnHDid; +}
View Code

C # read hard disk information ManagementClass class

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.