-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSystemInfo.cs
89 lines (79 loc) · 3.63 KB
/
SystemInfo.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Management;
using System.ServiceProcess;
using static ZenStates.Core.Cpu;
namespace ZenStates.Core
{
[Serializable]
public class SystemInfo
{
private static CPUInfo cpuInfo;
public SystemInfo(CPUInfo info, SMU smu)
{
cpuInfo = info;
SmuVersion = smu.Version;
SmuTableVersion = smu.TableVersion;
try
{
ServiceController sc = new ServiceController("Winmgmt");
if (sc.Status != ServiceControllerStatus.Running)
throw new ManagementException(@"Windows Management Instrumentation service is not running");
ManagementScope scope = new ManagementScope(@"root\cimv2");
scope.Connect();
if (!scope.IsConnected)
throw new ManagementException(@"Failed to connect to root\cimv2");
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
foreach (ManagementBaseObject obj in searcher.Get())
{
MbVendor = ((string)obj["Manufacturer"]).Trim();
MbName = ((string)obj["Product"]).Trim();
}
searcher.Dispose();
searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
foreach (ManagementBaseObject obj in searcher.Get())
{
BiosVersion = ((string)obj["SMBIOSBIOSVersion"]).Trim();
}
searcher.Dispose();
}
catch (ManagementException ex)
{
Console.WriteLine("WMI: {0}", ex.Message);
}
}
public string CpuName => cpuInfo.cpuName ?? "N/A";
public string CodeName => cpuInfo.codeName.ToString();
public uint CpuId => cpuInfo.cpuid;
public uint BaseModel => cpuInfo.baseModel;
public uint ExtendedModel => cpuInfo.extModel;
public uint Model => cpuInfo.model;
public uint Stepping => cpuInfo.stepping;
// This is not working correctly, it needs mappings for each generation
// public string PackageType => $"{cpuInfo.packageType} ({(int)cpuInfo.packageType})";
public int FusedCoreCount => (int)cpuInfo.topology.cores;
public int PhysicalCoreCount => (int)cpuInfo.topology.physicalCores;
public int NodesPerProcessor => (int)cpuInfo.topology.cpuNodes;
public int Threads => (int)cpuInfo.topology.logicalCores;
public bool SMT => (int)cpuInfo.topology.threadsPerCore > 1;
// Disable for now, need revising
// public int CCDCount => (int)cpuInfo.topology.ccds;
// public int CCXCount => (int)cpuInfo.topology.ccxs;
// public int NumCoresInCCX => (int)cpuInfo.topology.coresPerCcx;
public string MbVendor { get; private set; }
public string MbName { get; private set; }
public string BiosVersion { get; private set; }
public uint SmuVersion { get; private set; }
public uint SmuTableVersion { get; private set; }
public uint PatchLevel => cpuInfo.patchLevel;
public string GetSmuVersionString() => SmuVersionToString(SmuVersion);
public string GetCpuIdString() => CpuId.ToString("X8").TrimStart('0');
private static string SmuVersionToString(uint ver)
{
if ((ver & 0xFF000000) > 0)
{
return $"{(ver >> 24) & 0xff}.{(ver >> 16) & 0xff}.{(ver >> 8) & 0xff}.{ver & 0xff}";
}
return $"{(ver >> 16) & 0xff}.{(ver >> 8) & 0xff}.{ver & 0xff}";
}
}
}