Search code examples
c#cudaopenclethereummining

How to check if the system has AMD or NVIDIA in C#?


I'm trying to make an Ethereum mining client using C#, and I need to check whether the system has AMD or NVIDIA. This is because the program needs to know whether it should mine Ethereum via CUDA or OpenCL.


Solution

  • You need to use System.Management Namespace (You can find under references/Assemblies)

    After adding namespace you need to navigate all properties of ManagementObject and navigate all properties of propertydata till founding description on name property.

    I wrote this solution for console app. You can adapt your solution.

    Try this:

     using System;
     using System.Management;
    
     namespace ConsoleApp1
     {
     class Program
     {
        static void Main(string[] args)
        {
            ManagementObjectSearcher searcher = new 
     ManagementObjectSearcher("SELECT * FROM Win32_DisplayConfiguration");
    
            string gc = "";
            foreach (ManagementObject obj in searcher.Get())
            {
                foreach (PropertyData prop in obj.Properties)
                {
                    if (prop.Name == "Description")
                    {
                        gc = prop.Value.ToString().ToUpper();
    
                        if (gc.Contains("INTEL") == true)
                        {
                          Console.WriteLine("Your Graphic Card is Intel");
                        }
                        else if (gc.Contains("AMD") == true)
                        {
                            Console.WriteLine("Your Graphic Card is AMD");
                        }
                        else if (gc.Contains("NVIDIA") == true)
                        {
                            Console.WriteLine("Your Graphic Card is NVIDIA");
                        }
                        else
                        {
                            Console.WriteLine("Your Graphic Card cannot recognized.");
    
                        }
                        Console.ReadLine();
                    }
                }
            }
        }
    }
    }