2009-01-26 60 views
10

我正在尋找以C#檢索計算機的Windows體驗評分。如果可能的話,我也想檢索每個組件的數字(圖形,RAM等)檢索Windows體驗評分

這可能嗎?

回答

7

每當用戶經過控制面板來計算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> 
... 
+0

由於微軟刪除控制面板中的Windows體驗索引頁在Windows 8開始,你首先需要生成的數據存儲新的文件。有關詳細信息,請參閱此處:http://www.hanselman.com/blog/CalculateYourWEIWindowsExperienceIndexUnderWindows81.aspx – Surfbutler 2014-11-24 09:54:26

1

Here是VB.NET的一個片段。轉換爲C#(使用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; 
} 

我想它只會返回整體評分,但希望它至少能讓你開始。它可能只是一個改變文件名/參數來獲得個人評分的問題。

4

同樣的,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);