-
Notifications
You must be signed in to change notification settings - Fork 22
/
WMI_Processor_Information.cs
207 lines (187 loc) · 6.2 KB
/
WMI_Processor_Information.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
using System;
using System.Management;
namespace WMI_ProcessorInformation
{
public class WMI_Processor_Information
{
//Get the Caption of the Cpu (some rando-memum of the Cpu)
public static string GetCpuCaption()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Processor");
foreach (ManagementObject queryObj in searcher.Get())
{
return queryObj["Caption"].ToString();
}
}
catch (Exception e)
{
return null;
}
return null;
}
//Get the current anme of the Cpu
public static string GetCpuName()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Processor");
foreach (ManagementObject queryObj in searcher.Get())
{
return queryObj["name"].ToString();
}
}
catch (ManagementException e)
{
return null;
}
return null;
}
//Get the current operating voltage of the Cpu
public static int GetCpuVoltage()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Processor");
foreach (ManagementObject queryObj in searcher.Get())
{
return Convert.ToInt32(queryObj["CurrentVoltage"]);
}
}
catch (Exception e)
{
return -1;
}
return -1;
}
//Dual core? Quad-core? "Many-core"? http://en.wikipedia.org/wiki/Many-core_processing_unit
public static int GetCpuCores()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Processor");
foreach (ManagementObject queryObj in searcher.Get())
{
return Convert.ToInt32(queryObj["NumberOfCores"]);
}
}
catch (ManagementException e)
{
return -1;
}
return -1;
}
//Cpu serial
public static string GetCpuId()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Processor");
foreach (ManagementObject queryObj in searcher.Get())
{
return queryObj["ProcessorId"].ToString();
}
}
catch (ManagementException e)
{
return null;
}
return null;
}
//Cpu socket designation, more info here: http://en.wikipedia.org/wiki/CPU_socket
public static string GetCpuSocketDesignation()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Processor");
foreach (ManagementObject queryObj in searcher.Get())
{
return queryObj["SocketDesignation"].ToString();
}
}
catch (Exception e)
{
return null;
}
return null;
}
// Intel vs AMD :)
public static string GetCpuManufacturer()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Processor");
foreach (ManagementObject queryObj in searcher.Get())
{
return queryObj["Manufacturer"].ToString();
}
}
catch (Exception e)
{
return null;
}
return null;
}
//think hyper-threading
public static int GetCpuNumberOfLogicalProcessors()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Processor");
foreach (ManagementObject queryObj in searcher.Get())
{
return Convert.ToInt32(queryObj["NumberOfLogicalProcessors"]);
}
}
catch (Exception e)
{
return -1;
}
return -1;
}
public static int GetCpuClockSpeed()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Processor");
foreach (ManagementObject queryObj in searcher.Get())
{
return Convert.ToInt32(queryObj["CurrentClockSpeed"]);
}
}
catch (Exception e)
{
return -1;
}
return -1;
}
//Reads whether you are running a 32 or 64 Bit system
public static int GetCpuDataWidth()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Processor");
foreach (ManagementObject queryObj in searcher.Get())
{
return Convert.ToInt32(queryObj["DataWidth"]);
}
}
catch (Exception e)
{
return -1;
}
return -1;
}
}
}