检索 Windows 体验评级

发布于 2024-07-12 04:10:44 字数 83 浏览 5 评论 0原文

我希望在 C# 中检索计算机的 Windows 体验评级。 如果可能的话,我还想检索每个组件(图形、RAM 等)的编号。

这可能吗?

I'm looking to retrieve a machine's windows experience rating in C#. If possible I would also like to retrieve the numbers for each component (Graphics, RAM etc.)

Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你怎么敢 2024-07-19 04:10:44

每次用户通过控制面板计算 Windows 体验评级时,系统都会在 %Windows%\Performance\WinSAT\DataStore\ 中创建一个新文件,

您需要找到最新的文件(它们是首先以最重要的日期命名,因此查找最新文件很简单)。

这些文件是 xml 文件,很容易使用 XmlReader 或其他 xml 解析器进行解析。

您感兴趣的部分是 WinSAT\WinSPR,并且在单个部分中包含所有分数。 例如

<WinSAT>
    <WinSPR>
        <SystemScore>3.7</SystemScore> 
        <MemoryScore>5.9</MemoryScore> 
        <CpuScore>5.2</CpuScore> 
        <CPUSubAggScore>5.1</CPUSubAggScore> 
        <VideoEncodeScore>5.3</VideoEncodeScore> 
        <GraphicsScore>3.9</GraphicsScore> 
        <GamingScore>3.7</GamingScore> 
        <DiskScore>5.2</DiskScore> 
    </WinSPR>
...

Every time the user goes through control panel to calculate the Windows Experience Rating, the system creates a new file in %Windows%\Performance\WinSAT\DataStore\

You need to find the most recent file (they are named with the most significant date first, so finding the latest file is trivial).

These files are xml files and are easy to parse with XmlReader or other xml parser.

The section you are interested in is WinSAT\WinSPR and contains all the scores in a single section. E.g.

<WinSAT>
    <WinSPR>
        <SystemScore>3.7</SystemScore> 
        <MemoryScore>5.9</MemoryScore> 
        <CpuScore>5.2</CpuScore> 
        <CPUSubAggScore>5.1</CPUSubAggScore> 
        <VideoEncodeScore>5.3</VideoEncodeScore> 
        <GraphicsScore>3.9</GraphicsScore> 
        <GamingScore>3.7</GamingScore> 
        <DiskScore>5.2</DiskScore> 
    </WinSPR>
...
月亮坠入山谷 2024-07-19 04:10:44

与 LINQ 相同:

var dirName = Environment.ExpandEnvironmentVariables(@"%WinDir%\Performance\WinSAT\DataStore\");
var dirInfo = new DirectoryInfo(dirName);
var file = dirInfo.EnumerateFileSystemInfos("*Formal.Assessment*.xml")
    .OrderByDescending(fi => fi.LastWriteTime)
    .FirstOrDefault();

if (file == null)
    throw new FileNotFoundException("WEI assessment xml not found");

var doc = XDocument.Load(file.FullName);

Console.WriteLine("Processor: " + doc.Descendants("CpuScore").First().Value);
Console.WriteLine("Memory (RAM): " + doc.Descendants("MemoryScore").First().Value);
Console.WriteLine("Graphics: " + doc.Descendants("GraphicsScore").First().Value);
Console.WriteLine("Gaming graphics: " + doc.Descendants("GamingScore").First().Value);
Console.WriteLine("Primary hard disk: " + doc.Descendants("DiskScore").First().Value);
Console.WriteLine("Base score: " + doc.Descendants("SystemScore").First().Value);

Same with LINQ:

var dirName = Environment.ExpandEnvironmentVariables(@"%WinDir%\Performance\WinSAT\DataStore\");
var dirInfo = new DirectoryInfo(dirName);
var file = dirInfo.EnumerateFileSystemInfos("*Formal.Assessment*.xml")
    .OrderByDescending(fi => fi.LastWriteTime)
    .FirstOrDefault();

if (file == null)
    throw new FileNotFoundException("WEI assessment xml not found");

var doc = XDocument.Load(file.FullName);

Console.WriteLine("Processor: " + doc.Descendants("CpuScore").First().Value);
Console.WriteLine("Memory (RAM): " + doc.Descendants("MemoryScore").First().Value);
Console.WriteLine("Graphics: " + doc.Descendants("GraphicsScore").First().Value);
Console.WriteLine("Gaming graphics: " + doc.Descendants("GamingScore").First().Value);
Console.WriteLine("Primary hard disk: " + doc.Descendants("DiskScore").First().Value);
Console.WriteLine("Base score: " + doc.Descendants("SystemScore").First().Value);
老子叫无熙 2024-07-19 04:10:44

这里是 VB.NET 的代码片段。 转换为C#(使用这个,我还没有实际测试过代码还没有,虽然看起来没问题)。

/// <summary>
/// Gets the base score of a computer running Windows Vista or higher.
/// </summary>
/// <returns>The String Representation of Score, or False.</returns>
/// <remarks></remarks>
public string GetBaseScore()
{
    // Check if the computer has a \WinSAT dir.
    if (System.IO.Directory.Exists("C:\\Windows\\Performance\\WinSAT\\DataStore"))
    { 
        // Our method to get the most recently updated score.
        // Because the program makes a new XML file on every update of the score,
        // we need to calculate the most recent, just incase the owner has upgraded.
        System.IO.DirectoryInfo Dir = new System.IO.DirectoryInfo("C:\\Windows\\Performance\\WinSAT\\DataStore");
        System.IO.FileInfo[] fileDir = null;
        System.IO.FileInfo fileMostRecent = default(IO.FileInfo);
        System.DateTime LastAccessTime = default(System.DateTime);
        string LastAccessPath = string.Empty;
        fileDir = Dir.GetFiles;

        // Loop through the files in the \WinSAT dir to find the newest one.
        foreach (var fileMostRecent in fileDir)
        {
            if (fileMostRecent.LastAccessTime >= LastAccessTime)
            {
                LastAccessTime = fileMostRecent.LastAccessTime;
                LastAccessPath = fileMostRecent.FullName;
            }
        }

        // Create an XmlTextReader instance.
        System.Xml.XmlTextReader xmlReadScore = new System.Xml.XmlTextReader(LastAccessPath);

        // Disable whitespace handling so we don't read over them
        xmlReadScore.WhitespaceHandling = System.Xml.WhitespaceHandling.None;

        // We need to get to the 25th tag, "WinSPR".
        for (int i = 0; i <= 26; i++)
        {
            xmlReadScore.Read();
        }

        // Create a string variable, so we can clean up without any mishaps.
        string SystemScore = xmlReadScore.ReadElementString("SystemScore");

        // Clean up.
        xmlReadScore.Close();

        return SystemScore;
    }

    // Unsuccessful.
    return false;
}

我想它只会返回总体评分,但希望它至少能让您开始。 可能只需更改文件名/参数即可获得单独的评级。

Here is a snippet for VB.NET. Converted to C# (using this, I haven't actually tested the code yet, though it looks to be fine).

/// <summary>
/// Gets the base score of a computer running Windows Vista or higher.
/// </summary>
/// <returns>The String Representation of Score, or False.</returns>
/// <remarks></remarks>
public string GetBaseScore()
{
    // Check if the computer has a \WinSAT dir.
    if (System.IO.Directory.Exists("C:\\Windows\\Performance\\WinSAT\\DataStore"))
    { 
        // Our method to get the most recently updated score.
        // Because the program makes a new XML file on every update of the score,
        // we need to calculate the most recent, just incase the owner has upgraded.
        System.IO.DirectoryInfo Dir = new System.IO.DirectoryInfo("C:\\Windows\\Performance\\WinSAT\\DataStore");
        System.IO.FileInfo[] fileDir = null;
        System.IO.FileInfo fileMostRecent = default(IO.FileInfo);
        System.DateTime LastAccessTime = default(System.DateTime);
        string LastAccessPath = string.Empty;
        fileDir = Dir.GetFiles;

        // Loop through the files in the \WinSAT dir to find the newest one.
        foreach (var fileMostRecent in fileDir)
        {
            if (fileMostRecent.LastAccessTime >= LastAccessTime)
            {
                LastAccessTime = fileMostRecent.LastAccessTime;
                LastAccessPath = fileMostRecent.FullName;
            }
        }

        // Create an XmlTextReader instance.
        System.Xml.XmlTextReader xmlReadScore = new System.Xml.XmlTextReader(LastAccessPath);

        // Disable whitespace handling so we don't read over them
        xmlReadScore.WhitespaceHandling = System.Xml.WhitespaceHandling.None;

        // We need to get to the 25th tag, "WinSPR".
        for (int i = 0; i <= 26; i++)
        {
            xmlReadScore.Read();
        }

        // Create a string variable, so we can clean up without any mishaps.
        string SystemScore = xmlReadScore.ReadElementString("SystemScore");

        // Clean up.
        xmlReadScore.Close();

        return SystemScore;
    }

    // Unsuccessful.
    return false;
}

I guess it only returns the overall rating, but hopefully it should get you started at least. It may only be a matter of changing a filename/parameter to get the individual ratings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文