代码之家  ›  专栏  ›  技术社区  ›  Ray Booysen

检索Windows体验分级

  •  10
  • Ray Booysen  · 技术社区  · 17 年前

    我想用C#检索机器的windows体验等级。如果可能,我还想检索每个组件的编号(图形、RAM等)

    3 回复  |  直到 17 年前
        1
  •  7
  •   Sam Meldrum    17 年前

    每次用户通过控制面板计算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>
    ...
    
        2
  •  4
  •   SlavaGu    14 年前

    与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);
    
        3
  •  1
  •   Noldorin    17 年前

    Here this ,我还没有实际测试代码,尽管看起来还不错)。

    /// <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;
    }
    

    我猜它只会返回整体评分,但希望它至少能让你开始。这可能只是更改文件名/参数以获得单个评级的问题。