-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathComputerInformationFetcher.cs
More file actions
59 lines (49 loc) · 2.82 KB
/
ComputerInformationFetcher.cs
File metadata and controls
59 lines (49 loc) · 2.82 KB
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
using Microsoft.Management.Infrastructure;
using Microsoft.Management.Infrastructure.Options;
namespace ComputerHardwareIds
{
public static class ComputerInformationFetcher
{
public static (string Manufacturer,
string Family,
string ProductName,
string SKUNumber,
string BIOSVendor,
string BaseboardManufacturer,
string BaseboardProduct,
ushort EnclosureType,
string BIOSVersion,
byte BIOSMajorRelease,
byte BIOSMinorRelease) FetchComputerInformation()
{
using DComSessionOptions dcomSessionOptions = new();
using CimSession cimSession = CimSession.Create("localhost", dcomSessionOptions);
CimInstance result = cimSession.QueryInstances(@"root\cimv2", "WQL", "SELECT * FROM Win32_BIOS").Single();
string BIOSVendor = (string)result.CimInstanceProperties["Manufacturer"].Value;
string BIOSVersionString = (string)result.CimInstanceProperties["SMBIOSBIOSVersion"].Value;
byte SystemBIOSMajorRelease = (byte)result.CimInstanceProperties["SystemBiosMajorVersion"].Value;
byte SystemBIOSMinorRelease = (byte)result.CimInstanceProperties["SystemBiosMinorVersion"].Value;
result = cimSession.QueryInstances(@"root\cimv2", "WQL", "SELECT * FROM Win32_ComputerSystem").Single();
string SystemManufacturer = (string)result.CimInstanceProperties["Manufacturer"].Value;
string SystemFamily = (string)result.CimInstanceProperties["SystemFamily"].Value;
string SystemProductName = (string)result.CimInstanceProperties["Model"].Value;
string SKUNumber = (string)result.CimInstanceProperties["SystemSKUNumber"].Value;
result = cimSession.QueryInstances(@"root\cimv2", "WQL", "SELECT * FROM Win32_SystemEnclosure").Single();
ushort SystemEnclosureorChassisType = ((ushort[])result.CimInstanceProperties["ChassisTypes"].Value)[0];
result = cimSession.QueryInstances(@"root\cimv2", "WQL", "SELECT * FROM Win32_BaseBoard").Single();
string BaseboardManufacturer = (string)result.CimInstanceProperties["Manufacturer"].Value;
string BaseboardProductName = (string)result.CimInstanceProperties["Product"].Value;
return (SystemManufacturer,
SystemFamily,
SystemProductName,
SKUNumber,
BIOSVendor,
BaseboardManufacturer,
BaseboardProductName,
SystemEnclosureorChassisType,
BIOSVersionString,
SystemBIOSMajorRelease,
SystemBIOSMinorRelease);
}
}
}