版上的各位高手好,我想要寫一個簡單的程式可以查詢系統的顯示卡,在網路上找到這段程式,經測試後使用主控台應用程式是可以使用的,可以顯示出目前顯卡的裝置
using System;
using System.Management;
namespace Test
{
internal class Program
{
static void Main(string[] args)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_VideoController");
string graphicsCard = string.Empty;
foreach (ManagementObject obj in searcher.Get())
{
//if (obj["CurrentBitsPerPixel"] != null && obj["CurrentHorizontalResolution"] != null)
//{
// graphicsCard = obj["Name"].ToString();
//}
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_VideoController instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("Description: {0}", obj["Description"]);
}
}
}
}
}
但將一樣的code改放進Windows Form 應用程式後,在執行時卻會跑出下面這段error (P.S. 我都有載入參考"System.Management")
System.PlatformNotSupportedException: 'System.Management currently is only supported for Windows desktop applications.'