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

霸气de小男生 提交于 2019-12-24 20:29:17

问题


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.


回答1:


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();
                }
            }
        }
    }
}
}


来源:https://stackoverflow.com/questions/49348026/how-to-check-if-the-system-has-amd-or-nvidia-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!