Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检索Windows体验分级_C#_Rating - Fatal编程技术网

C# 检索Windows体验分级

C# 检索Windows体验分级,c#,rating,C#,Rating,我想用C#检索机器的windows体验等级。如果可能,我还想检索每个组件的编号(图形、RAM等) 这可能吗?是VB.NET的一个代码段。转换为C#(使用,我还没有实际测试代码,尽管看起来不错) // ///获取运行Windows Vista或更高版本的计算机的基本分数。 /// ///Score或False的字符串表示形式。 /// 公共字符串GetBaseScore() { //检查计算机是否有\WinSAT目录。 如果(System.IO.Directory.Exists(“C:\\Wi

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

这可能吗?

是VB.NET的一个代码段。转换为C#(使用,我还没有实际测试代码,尽管看起来不错)

//
///获取运行Windows Vista或更高版本的计算机的基本分数。
/// 
///Score或False的字符串表示形式。
/// 
公共字符串GetBaseScore()
{
//检查计算机是否有\WinSAT目录。
如果(System.IO.Directory.Exists(“C:\\Windows\\Performance\\WinSAT\\DataStore”))
{ 
//我们的方法是获取最近更新的分数。
//因为程序在每次更新分数时都会生成一个新的XML文件,
//我们需要计算最新的,以防万一所有者已升级。
System.IO.DirectoryInfo Dir=new System.IO.DirectoryInfo(“C:\\Windows\\Performance\\WinSAT\\DataStore”);
System.IO.FileInfo[]fileDir=null;
System.IO.FileInfo fileMostRecent=默认值(IO.FileInfo);
System.DateTime LastAccessTime=默认值(System.DateTime);
string LastAccessPath=string.Empty;
fileDir=Dir.GetFiles;
//循环\WinSAT目录中的文件以查找最新的文件。
foreach(fileDir中的var fileMostRecent)
{
如果(fileMostRecent.LastAccessTime>=LastAccessTime)
{
LastAccessTime=fileMostRecent.LastAccessTime;
LastAccessPath=fileMostRecent.FullName;
}
}
//创建一个XmlTextReader实例。
System.Xml.XmlTextReader xmlReadScore=新的System.Xml.XmlTextReader(LastAccessPath);
//禁用空白处理,这样我们就不会阅读它们
xmlReadScore.WhitespaceHandling=System.Xml.WhitespaceHandling.None;
//我们需要到达第25个标签“WinSPR”。

对于(int i=0;i,每次用户通过控制面板计算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>
...

3.7
5.9
5.2
5.1
5.3
3.9
3.7
5.2
...
与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);

随着Microsoft从Windows 8以后的控制面板中删除Windows体验索引页,您首先需要在数据存储中生成一个新文件。有关详细信息,请参阅此处:
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);