1

我正在尝试访问 winsat 数据。WMI 有一个类。

Win32_WinSAT

我正在尝试使用查询获取最近的数据

"SELECT * FROM Win32_WinSAT WHERE TimeTaken='MostRecentAssessment'"

它在 PowerShell 甚至在 WMIExplorer 中都可以正常工作,但是在使用 System.Management 类的 C# 代码中它不能正常工作

我的代码如下

class WinSatData
    {
        public double MemoryScore { get; set; }
        public double CPUScore { get; set; }
        public double D3DScore { get; set; }
        public double DiskScore { get; set; }
        public double GraphicsScore { get; set; }
    }
class Program
    {
        static void Main(string[] args)
        {
            List<WinSatData> winsat = new List<WinSatData>();
            ManagementScope scope = new ManagementScope("\\\\localhost\\root\\cimv2");
            scope.Connect();

            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_WinSAT WHERE TimeTaken='MostRecentAssessment'");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
            ManagementObjectCollection collection = searcher.Get();

            foreach (ManagementObject m in collection) {
                WinSatData win = new WinSatData();
                win.CPUScore = (Convert.ToDouble(m["CPUScore"]));
                win.MemoryScore = (Convert.ToDouble(m["MemoryScore"]));
                win.D3DScore = (Convert.ToDouble(m["D3DScore"]));
                win.GraphicsScore = (Convert.ToDouble(m["GraphicsScore"]));
                winsat.Add(win);
            }
            string outout = JsonConvert.SerializeObject(winsat);
            Console.WriteLine(outout);
            Console.ReadKey();
        }
    }

Management 对象中的所有值都为零。我仔细检查了 ManagementObject m 的属性。属性名称是正确的,但值是错误的。

输出如下:

[{"MemoryScore":0.0,"CPUScore":0.0,"D3DScore":0.0,"DiskScore":0.0,"GraphicsScore":0.0}]

请帮助我访问 WinSAT。

4

0 回答 0