2009-01-26 15 views
10

मैं सी # में मशीन की विंडोज़ अनुभव रेटिंग पुनर्प्राप्त करना चाहता हूं। यदि संभव हो तो मैं प्रत्येक घटक (ग्राफिक्स, रैम इत्यादि) के लिए संख्याएं भी पुनर्प्राप्त करना चाहूंगाविंडोज अनुभव रेटिंग पुनर्प्राप्त करें

क्या यह संभव है?

उत्तर

7

हर बार जब उपयोगकर्ता विंडोज अनुभव रेटिंग गणना करने के लिए नियंत्रण कक्ष के माध्यम से चला जाता है, प्रणाली, %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

के रूप में माइक्रोसॉफ्ट विंडोज 8 के बाद में नियंत्रण कक्ष से विंडोज अनुभव सूचकांक पृष्ठ हटा दिया, आप पहली बार डेटा की दुकान में एक नई फ़ाइल जनरेट करना होगा। अधिक जानकारी के लिए यहां देखें: http://www.hanselman.com/blog/CalculateYourWEIWindowsExperienceIndexUnderWindows81.aspx – Surfbutler

1

Here वीबी.नेट के लिए एक स्निपेट है। 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); 
संबंधित मुद्दे