C# 'de bir makinenin windows deneyim derecesi almak istiyorum. Mümkünse, her bir bileşen için (Grafik, RAM vb.) Sayıları da almak istiyorum (Windows Deneyim Puanlaması Alınır
Bu mümkün mü?
C# 'de bir makinenin windows deneyim derecesi almak istiyorum. Mümkünse, her bir bileşen için (Grafik, RAM vb.) Sayıları da almak istiyorum (Windows Deneyim Puanlaması Alınır
Bu mümkün mü?
kullanıcı, Windows Deneyim Puanı hesaplanması için kontrol paneli geçer Her zaman, sistem, %Windows%\Performance\WinSAT\DataStore\
Sen (ilk en önemli tarihi ile adlandırılır en son dosyayı bulmak gerekir
yeni bir dosya oluşturur en son dosya bulmak çok önemlidir).
Bu dosyalar xml dosyalarıdır ve XmlReader veya diğer xml ayrıştırıcılarıyla ayrıştırılması kolaydır.
İlgilendiğiniz bölüm WinSAT\WinSPR
olup tüm bölümleri tek bir bölümden içerir. Örneğin. LINQ ile aynı
<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>
...
Here VB.NET için bir parçacıktır. C# 'ye dönüştürülmüş (this kullanarak, henüz kodu test etmedim, yine de iyi görünüyor).
/// <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;
}
Sadece genel notu döndürür, ancak umarım en azından başlamanızı sağlamış olur. Bireysel derecelendirmeleri almak için yalnızca bir dosya adını/parametresini değiştirmek sorun olabilir.
:
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);
Microsoft itibaren Windows 8'de Denetim Masası'ndan Windows Deneyimi Dizini kaldırdık gibi, ilk olarak veri deposunda yeni bir dosya oluşturmak gerekir. Daha fazla bilgi için buraya bakın: http://www.hanselman.com/blog/CalculateYourWEIWindowsExperienceIndexUnderWindows81.aspx – Surfbutler