background
In the previous article, the computer graphics card information has been obtained through C#, and the value is empty when obtaining the core code information of the graphics card.
Therefore, this article obtains core code information in another way.
【Driver Series】C# Gets the graphics card information of computer hardware
Third-party tools
GPU-Z is a commonly used free tool for obtaining and displaying detailed information about graphics cards (graphics processing units, GPUs) in your computer. It can provide real-time readings of graphics card model, driver version, memory size, sensor data (such as temperature, fan speed, etc.) and other related hardware information.
Graphics card information
GPU-Z displays detailed information about the graphics card, including graphics card manufacturer, model, memory type and size, clock speed, etc.
Sensor monitoring
It can read and display various sensor data of the graphics card, such as temperature, load, fan speed, power consumption, etc. This data helps you understand the performance and status of your graphics card.
Instant read and update
GPU-Z can read hardware information in real time and update automatically when graphics card or driver changes.
Export and share
You can export the output of GPU-Z as a text file for easy sharing with others or saving for subsequent analysis.
Supports multiple graphics cards
GPU-Z can identify and display information on a variety of graphics card brands and models, including graphics cards from manufacturers such as NVIDIA, AMD and Intel.
Implement code
The acquisition of core code may vary depending on the graphics card manufacturer and driver.
Here is an alternative way to get the core code, which uses the command line version of the GPU-Z tool:
1. First, download and install the command line version of the GPU-Z tool (GPU-Z CLI). You can use the official website of GPU-Z (/gpuz/) find the tool on and make sure to add its path to the system environment variable.
2. In C# code, use classes to execute GPU-Z commands and capture output.
using System; using ; class Program { static void Main() { // Execute the GPU-Z command line and capture the output results Process process = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "", // The path to the GPU-Z command line Arguments = "-dump=nogpu -txt=", // Specify the output format as a text file RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true }; = startInfo; (); (); // Read the core code in the output file string outputFilePath = ""; // Specify the path to the output file string[] lines = (outputFilePath); string coreName = ""; foreach (string line in lines) { if (("GPU")) { // The format of the line where the core code is: GPU: [core code] coreName = (':')[1].Trim(); break; } } ("Core Code: " + coreName); } }
Knowledge Supplement
Here is the code for reading hardware parameters:
public class OSInformation { public string OSName { get; set; } public string OSType { get; set; } public string OSSerialNumber { get; set; } public string ComputerName { get; set; } public string LogonUserName { get; set; } } public class HInformaiton { public string MainboardName { get; set; } public string MemorySize { get; set; } public string HarddiskSize { get; set; } public string VideocardName { get; set; } public string SoundcardName { get; set; } public string NetworkcardName { get; set; } public string ManufacturerName { get; set; } public string ManufactureDate { get; set; } } public class SInformation { public string VRV { get; set; } public string QAX { get; set; } public string WPS { get; set; } } public class WInformation { public string IP { get; set; } public string Subnetmask { get; set; } public string Gateway { get; set; } } class HardwareInformation { public static string GetJsonStr() { string ReturnStrJson = ""; var HInfor = new HInformaiton { MainboardName ="unknown", MemorySize = "unknown", HarddiskSize = "unknown", VideocardName = "unknown", SoundcardName = "unknown", NetworkcardName = "unknown",ManufacturerName= "unknown", ManufactureDate= "unknown" }; //Motherboard information try { ManagementObjectSearcher myMainboard = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard"); foreach (ManagementObject board in ()) { = board["Product"].ToString(); //break; } } catch (Exception ex) { = "unknown"; } //Memory information try { ManagementObjectSearcher myMemory = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory"); //Define the total memory size variable double MemorySize = 0; foreach (ManagementObject obj in ()) { //Convert memory size to G units MemorySize += (obj["Capacity"]) / 1024 / 1024 / 1024; } = ()+"G"; } catch (ManagementException e) { = "unknown"; } //Hard disk information try { //Get all hard disk information of this machine ManagementObjectSearcher myHarddisk = new ManagementObjectSearcher("select * from Win32_DiskDrive"); foreach (ManagementObject drive in ()) { //Get hard disk capacity var capacity = ((drive["Size"]) / 1024 / 1024 / 1024).ToString("0.00") + "G"; //Get hard disk type var mediaType = drive["MediaType"]; = () + "|" + (); } } catch (Exception ex) { = "unknown"; } //Graphics card information try { ManagementObjectSearcher myVideoObject = new ManagementObjectSearcher("select * from Win32_VideoController"); foreach (ManagementObject obj in ()) { = obj["Name"].ToString(); } } catch (ManagementException e) { // = "unknown"; } //Sound card information try { // Create WMI search object ManagementObjectSearcher mySoundcard = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_SoundDevice"); // traverse the search results foreach (ManagementObject mo in ()) { // Get the sound card name = ("Name").ToString(); } } catch (ManagementException e) { = "unknown"; } //Network card information (Mac address) try { // Get local network interface information NetworkInterface[] nics = (); foreach (NetworkInterface adapter in nics) { // If it is an RJ45 network card if ( == ) { string S1 = (string); if (("PCI")){ = S1; } } } } catch (ManagementException e) { = "unknown"; } //Get the manufacturer and production date try { //Get the manufacturer ManagementObjectSearcher ManufacturerInfo = new ManagementObjectSearcher("select * from Win32_ComputerSystem"); foreach (ManagementObject obj in ()) { = obj["Manufacturer"].ToString(); } //Get production date ConnectionOptions options = new ConnectionOptions(); ManagementScope scope = new ManagementScope("\\\\.\\root\\cimv2", options); ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_BIOS"); ManagementObjectSearcher BoisInfo = new ManagementObjectSearcher(scope, query); foreach (ManagementObject mo in ()) { string StrManufactureDate = mo["ReleaseDate"].ToString().Substring(0, 8); DateTime DT = (StrManufactureDate, "yyyyMMdd", ); = ("{0:d}", DT); } } catch (Exception e) { } ReturnStrJson = (HInfor); return ReturnStrJson; } }
Need to add a reference:
using Microsoft.Win32; using ; using ; using ;
The call is relatively simple:
string JsonStr; //Hardware information JsonStr = (); var ObjHardware = <Dictionary<string, object>>(JsonStr); ListBox listbox1 = [0].Controls["listbox1"] as ListBox; ("Motherboard:"+ ObjHardware["MainboardName"]); ("Memory:" + ObjHardware["MemorySize"]); ("harddisk:" + ObjHardware["HarddiskSize"]); ("Graphics Card:" + ObjHardware["VideocardName"]); ("Sound Card:" + ObjHardware["SoundcardName"]); ("Network Card:" + ObjHardware["NetworkcardName"]); ("Computer Manufacturer:" + ObjHardware["ManufacturerName"]); ("Computer production date:" + ObjHardware["ManufactureDate"]);
This is the article about C# to obtain the core code information of computer hardware graphics cards. For more related C# to obtain computer graphics cards, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!