@oxmc/node-smbios 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +473 -0
- package/binding.gyp +49 -0
- package/example.js +94 -0
- package/index.js +33 -0
- package/package.json +70 -0
- package/src/binding.cpp +266 -0
- package/src/linux/smbios_linux.cpp +214 -0
- package/src/mac/smbios_macos.cpp +224 -0
- package/src/smbios_common.cpp +70 -0
- package/src/smbios_common.h +107 -0
- package/src/windows/smbios_windows.cpp +255 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
#include "../smbios_common.h"
|
|
2
|
+
|
|
3
|
+
#ifdef __APPLE__
|
|
4
|
+
|
|
5
|
+
#include <IOKit/IOKitLib.h>
|
|
6
|
+
#include <CoreFoundation/CoreFoundation.h>
|
|
7
|
+
#include <string>
|
|
8
|
+
|
|
9
|
+
namespace smbios {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Helper function to get string property from IORegistry
|
|
13
|
+
*/
|
|
14
|
+
std::string GetIORegistryString(const char* service, const char* property) {
|
|
15
|
+
std::string result;
|
|
16
|
+
|
|
17
|
+
io_service_t platformExpert = IOServiceGetMatchingService(
|
|
18
|
+
kIOMasterPortDefault,
|
|
19
|
+
IOServiceMatching(service)
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
if (platformExpert) {
|
|
23
|
+
CFTypeRef cfProperty = IORegistryEntryCreateCFProperty(
|
|
24
|
+
platformExpert,
|
|
25
|
+
CFStringCreateWithCString(kCFAllocatorDefault, property, kCFStringEncodingUTF8),
|
|
26
|
+
kCFAllocatorDefault,
|
|
27
|
+
0
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
if (cfProperty) {
|
|
31
|
+
if (CFGetTypeID(cfProperty) == CFStringGetTypeID()) {
|
|
32
|
+
CFStringRef cfString = (CFStringRef)cfProperty;
|
|
33
|
+
CFIndex length = CFStringGetLength(cfString);
|
|
34
|
+
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
|
|
35
|
+
char* buffer = new char[maxSize];
|
|
36
|
+
|
|
37
|
+
if (CFStringGetCString(cfString, buffer, maxSize, kCFStringEncodingUTF8)) {
|
|
38
|
+
result = buffer;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
delete[] buffer;
|
|
42
|
+
} else if (CFGetTypeID(cfProperty) == CFDataGetTypeID()) {
|
|
43
|
+
CFDataRef cfData = (CFDataRef)cfProperty;
|
|
44
|
+
CFIndex length = CFDataGetLength(cfData);
|
|
45
|
+
const UInt8* bytes = CFDataGetBytePtr(cfData);
|
|
46
|
+
result = std::string((const char*)bytes, length);
|
|
47
|
+
|
|
48
|
+
// Remove null terminators
|
|
49
|
+
size_t pos = result.find('\0');
|
|
50
|
+
if (pos != std::string::npos) {
|
|
51
|
+
result = result.substr(0, pos);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
CFRelease(cfProperty);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
IOObjectRelease(platformExpert);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return TrimString(result);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Helper function to get data property as hex string (for UUID)
|
|
66
|
+
*/
|
|
67
|
+
std::string GetIORegistryUUID(const char* service, const char* property) {
|
|
68
|
+
std::string result;
|
|
69
|
+
|
|
70
|
+
io_service_t platformExpert = IOServiceGetMatchingService(
|
|
71
|
+
kIOMasterPortDefault,
|
|
72
|
+
IOServiceMatching(service)
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
if (platformExpert) {
|
|
76
|
+
CFTypeRef cfProperty = IORegistryEntryCreateCFProperty(
|
|
77
|
+
platformExpert,
|
|
78
|
+
CFStringCreateWithCString(kCFAllocatorDefault, property, kCFStringEncodingUTF8),
|
|
79
|
+
kCFAllocatorDefault,
|
|
80
|
+
0
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
if (cfProperty) {
|
|
84
|
+
if (CFGetTypeID(cfProperty) == CFStringGetTypeID()) {
|
|
85
|
+
CFStringRef cfString = (CFStringRef)cfProperty;
|
|
86
|
+
CFIndex length = CFStringGetLength(cfString);
|
|
87
|
+
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1;
|
|
88
|
+
char* buffer = new char[maxSize];
|
|
89
|
+
|
|
90
|
+
if (CFStringGetCString(cfString, buffer, maxSize, kCFStringEncodingUTF8)) {
|
|
91
|
+
result = buffer;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
delete[] buffer;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
CFRelease(cfProperty);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
IOObjectRelease(platformExpert);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return TrimString(result);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
BiosInfo GetBiosInfo() {
|
|
107
|
+
BiosInfo info;
|
|
108
|
+
|
|
109
|
+
// On macOS, BIOS info is limited
|
|
110
|
+
info.vendor = "Apple Inc.";
|
|
111
|
+
info.version = GetIORegistryString("IOPlatformExpertDevice", "version");
|
|
112
|
+
info.releaseDate = GetIORegistryString("IOPlatformExpertDevice", "release-date");
|
|
113
|
+
|
|
114
|
+
// Try getting boot ROM version
|
|
115
|
+
std::string bootRomVersion = GetIORegistryString("IOPlatformExpertDevice", "target-type");
|
|
116
|
+
if (!bootRomVersion.empty()) {
|
|
117
|
+
info.version = bootRomVersion;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Get ROM version
|
|
121
|
+
std::string romVersion = GetIORegistryString("IOPlatformExpertDevice", "version-major");
|
|
122
|
+
if (!romVersion.empty()) {
|
|
123
|
+
info.biosCharacteristics = "ROM Version: " + romVersion;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return info;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
SystemInfo GetSystemInfo() {
|
|
130
|
+
SystemInfo info;
|
|
131
|
+
|
|
132
|
+
info.manufacturer = "Apple Inc.";
|
|
133
|
+
info.productName = GetIORegistryString("IOPlatformExpertDevice", "model");
|
|
134
|
+
info.serialNumber = GetIORegistryString("IOPlatformExpertDevice", "IOPlatformSerialNumber");
|
|
135
|
+
info.uuid = GetIORegistryUUID("IOPlatformExpertDevice", "IOPlatformUUID");
|
|
136
|
+
|
|
137
|
+
// Get additional info
|
|
138
|
+
std::string modelName = GetIORegistryString("IOPlatformExpertDevice", "model-name");
|
|
139
|
+
if (!modelName.empty()) {
|
|
140
|
+
info.family = modelName;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
info.skuNumber = GetIORegistryString("IOPlatformExpertDevice", "model-number");
|
|
144
|
+
info.wakeUpType = GetIORegistryString("IOPlatformExpertDevice", "clock-frequency");
|
|
145
|
+
|
|
146
|
+
return info;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
BoardInfo GetBoardInfo() {
|
|
150
|
+
BoardInfo info;
|
|
151
|
+
|
|
152
|
+
info.manufacturer = "Apple Inc.";
|
|
153
|
+
info.product = GetIORegistryString("IOPlatformExpertDevice", "board-id");
|
|
154
|
+
info.serialNumber = GetIORegistryString("IOPlatformExpertDevice", "IOPlatformSerialNumber");
|
|
155
|
+
|
|
156
|
+
// Try to get more board info
|
|
157
|
+
std::string modelNumber = GetIORegistryString("IOPlatformExpertDevice", "model-number");
|
|
158
|
+
if (!modelNumber.empty()) {
|
|
159
|
+
info.version = modelNumber;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
info.assetTag = GetIORegistryString("IOPlatformExpertDevice", "target-type");
|
|
163
|
+
info.locationInChassis = GetIORegistryString("IOPlatformExpertDevice", "product-name");
|
|
164
|
+
|
|
165
|
+
return info;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
ProcessorInfo GetProcessorInfo() {
|
|
169
|
+
ProcessorInfo info;
|
|
170
|
+
|
|
171
|
+
// Get CPU info from sysctl or IORegistry
|
|
172
|
+
info.manufacturer = GetIORegistryString("IODeviceTree:/cpus/cpu@0", "vendor");
|
|
173
|
+
if (info.manufacturer.empty()) {
|
|
174
|
+
info.manufacturer = "Apple";
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
info.version = GetIORegistryString("IODeviceTree:/cpus/cpu@0", "name");
|
|
178
|
+
info.socketDesignation = GetIORegistryString("IOPlatformExpertDevice", "target-type");
|
|
179
|
+
info.processorType = GetIORegistryString("IODeviceTree:/cpus/cpu@0", "device_type");
|
|
180
|
+
info.processorFamily = GetIORegistryString("IOPlatformExpertDevice", "compatible");
|
|
181
|
+
|
|
182
|
+
// Note: More detailed CPU info would require sysctlbyname calls
|
|
183
|
+
info.maxSpeed = "N/A (use sysctl for detailed info)";
|
|
184
|
+
info.currentSpeed = "N/A";
|
|
185
|
+
info.coreCount = "N/A";
|
|
186
|
+
info.threadCount = "N/A";
|
|
187
|
+
info.l2CacheSize = "N/A";
|
|
188
|
+
info.l3CacheSize = "N/A";
|
|
189
|
+
|
|
190
|
+
return info;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
MemoryInfo GetMemoryInfo() {
|
|
194
|
+
MemoryInfo info;
|
|
195
|
+
|
|
196
|
+
// Note: Full implementation would use sysctlbyname
|
|
197
|
+
info.totalPhysicalMemory = "N/A (use sysctl hw.memsize)";
|
|
198
|
+
info.availablePhysicalMemory = "N/A";
|
|
199
|
+
info.totalVirtualMemory = "N/A";
|
|
200
|
+
info.availableVirtualMemory = "N/A";
|
|
201
|
+
info.memoryDevices = "N/A";
|
|
202
|
+
info.maxCapacity = "N/A";
|
|
203
|
+
|
|
204
|
+
return info;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
ChassisInfo GetChassisInfo() {
|
|
208
|
+
ChassisInfo info;
|
|
209
|
+
|
|
210
|
+
info.manufacturer = "Apple Inc.";
|
|
211
|
+
info.type = GetIORegistryString("IOPlatformExpertDevice", "product-name");
|
|
212
|
+
info.version = GetIORegistryString("IOPlatformExpertDevice", "version");
|
|
213
|
+
info.serialNumber = GetIORegistryString("IOPlatformExpertDevice", "IOPlatformSerialNumber");
|
|
214
|
+
info.assetTag = GetIORegistryString("IOPlatformExpertDevice", "model");
|
|
215
|
+
info.bootUpState = "Normal";
|
|
216
|
+
info.powerSupplyState = "Safe";
|
|
217
|
+
info.thermalState = "Safe";
|
|
218
|
+
|
|
219
|
+
return info;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
} // namespace smbios
|
|
223
|
+
|
|
224
|
+
#endif // __APPLE__
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#include "smbios_common.h"
|
|
2
|
+
#include <algorithm>
|
|
3
|
+
#include <cctype>
|
|
4
|
+
#include <fstream>
|
|
5
|
+
#include <sstream>
|
|
6
|
+
|
|
7
|
+
#ifdef _WIN32
|
|
8
|
+
#include <sys/stat.h>
|
|
9
|
+
#else
|
|
10
|
+
#include <sys/stat.h>
|
|
11
|
+
#include <unistd.h>
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
namespace smbios {
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Trim whitespace from both ends of a string
|
|
18
|
+
*/
|
|
19
|
+
std::string TrimString(const std::string& str) {
|
|
20
|
+
size_t start = 0;
|
|
21
|
+
size_t end = str.length();
|
|
22
|
+
|
|
23
|
+
// Trim from start
|
|
24
|
+
while (start < end && std::isspace(static_cast<unsigned char>(str[start]))) {
|
|
25
|
+
start++;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Trim from end
|
|
29
|
+
while (end > start && std::isspace(static_cast<unsigned char>(str[end - 1]))) {
|
|
30
|
+
end--;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return str.substr(start, end - start);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Check if a file exists
|
|
38
|
+
*/
|
|
39
|
+
bool FileExists(const std::string& path) {
|
|
40
|
+
#ifdef _WIN32
|
|
41
|
+
struct _stat buffer;
|
|
42
|
+
return (_stat(path.c_str(), &buffer) == 0);
|
|
43
|
+
#else
|
|
44
|
+
struct stat buffer;
|
|
45
|
+
return (stat(path.c_str(), &buffer) == 0);
|
|
46
|
+
#endif
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Read entire file contents
|
|
51
|
+
*/
|
|
52
|
+
std::string ReadFile(const std::string& path) {
|
|
53
|
+
std::ifstream file(path);
|
|
54
|
+
if (!file.is_open()) {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
std::stringstream buffer;
|
|
59
|
+
buffer << file.rdbuf();
|
|
60
|
+
std::string content = buffer.str();
|
|
61
|
+
|
|
62
|
+
// Remove trailing newlines
|
|
63
|
+
while (!content.empty() && (content.back() == '\n' || content.back() == '\r')) {
|
|
64
|
+
content.pop_back();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return TrimString(content);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
} // namespace smbios
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#ifndef SMBIOS_COMMON_H
|
|
2
|
+
#define SMBIOS_COMMON_H
|
|
3
|
+
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <vector>
|
|
6
|
+
|
|
7
|
+
namespace smbios {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* BIOS Information structure
|
|
11
|
+
*/
|
|
12
|
+
struct BiosInfo {
|
|
13
|
+
std::string vendor;
|
|
14
|
+
std::string version;
|
|
15
|
+
std::string releaseDate;
|
|
16
|
+
std::string biosCharacteristics;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* System Information structure
|
|
21
|
+
*/
|
|
22
|
+
struct SystemInfo {
|
|
23
|
+
std::string manufacturer;
|
|
24
|
+
std::string productName;
|
|
25
|
+
std::string serialNumber;
|
|
26
|
+
std::string uuid;
|
|
27
|
+
std::string skuNumber;
|
|
28
|
+
std::string family;
|
|
29
|
+
std::string wakeUpType;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Board/Baseboard Information structure
|
|
34
|
+
*/
|
|
35
|
+
struct BoardInfo {
|
|
36
|
+
std::string manufacturer;
|
|
37
|
+
std::string product;
|
|
38
|
+
std::string version;
|
|
39
|
+
std::string serialNumber;
|
|
40
|
+
std::string assetTag;
|
|
41
|
+
std::string locationInChassis;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Processor Information structure
|
|
46
|
+
*/
|
|
47
|
+
struct ProcessorInfo {
|
|
48
|
+
std::string manufacturer;
|
|
49
|
+
std::string version;
|
|
50
|
+
std::string socketDesignation;
|
|
51
|
+
std::string processorType;
|
|
52
|
+
std::string processorFamily;
|
|
53
|
+
std::string maxSpeed;
|
|
54
|
+
std::string currentSpeed;
|
|
55
|
+
std::string coreCount;
|
|
56
|
+
std::string threadCount;
|
|
57
|
+
std::string l2CacheSize;
|
|
58
|
+
std::string l3CacheSize;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Memory Information structure
|
|
63
|
+
*/
|
|
64
|
+
struct MemoryInfo {
|
|
65
|
+
std::string totalPhysicalMemory;
|
|
66
|
+
std::string availablePhysicalMemory;
|
|
67
|
+
std::string totalVirtualMemory;
|
|
68
|
+
std::string availableVirtualMemory;
|
|
69
|
+
std::string memoryDevices;
|
|
70
|
+
std::string maxCapacity;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Chassis Information structure
|
|
75
|
+
*/
|
|
76
|
+
struct ChassisInfo {
|
|
77
|
+
std::string manufacturer;
|
|
78
|
+
std::string type;
|
|
79
|
+
std::string version;
|
|
80
|
+
std::string serialNumber;
|
|
81
|
+
std::string assetTag;
|
|
82
|
+
std::string bootUpState;
|
|
83
|
+
std::string powerSupplyState;
|
|
84
|
+
std::string thermalState;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Platform-specific implementations
|
|
89
|
+
* These functions must be implemented for each platform
|
|
90
|
+
*/
|
|
91
|
+
BiosInfo GetBiosInfo();
|
|
92
|
+
SystemInfo GetSystemInfo();
|
|
93
|
+
BoardInfo GetBoardInfo();
|
|
94
|
+
ProcessorInfo GetProcessorInfo();
|
|
95
|
+
MemoryInfo GetMemoryInfo();
|
|
96
|
+
ChassisInfo GetChassisInfo();
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Utility functions
|
|
100
|
+
*/
|
|
101
|
+
std::string TrimString(const std::string& str);
|
|
102
|
+
bool FileExists(const std::string& path);
|
|
103
|
+
std::string ReadFile(const std::string& path);
|
|
104
|
+
|
|
105
|
+
} // namespace smbios
|
|
106
|
+
|
|
107
|
+
#endif // SMBIOS_COMMON_H
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
#include "../smbios_common.h"
|
|
2
|
+
|
|
3
|
+
#ifdef _WIN32
|
|
4
|
+
|
|
5
|
+
#define WIN32_LEAN_AND_MEAN
|
|
6
|
+
#include <windows.h>
|
|
7
|
+
#include <comdef.h>
|
|
8
|
+
#include <Wbemidl.h>
|
|
9
|
+
#include <string>
|
|
10
|
+
#include <vector>
|
|
11
|
+
|
|
12
|
+
#pragma comment(lib, "wbemuuid.lib")
|
|
13
|
+
|
|
14
|
+
namespace smbios {
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Helper class for WMI queries
|
|
18
|
+
*/
|
|
19
|
+
class WMIQuery {
|
|
20
|
+
private:
|
|
21
|
+
IWbemLocator* pLoc;
|
|
22
|
+
IWbemServices* pSvc;
|
|
23
|
+
bool initialized;
|
|
24
|
+
|
|
25
|
+
public:
|
|
26
|
+
WMIQuery() : pLoc(nullptr), pSvc(nullptr), initialized(false) {
|
|
27
|
+
// Initialize COM
|
|
28
|
+
HRESULT hres = CoInitializeEx(0, COINIT_MULTITHREADED);
|
|
29
|
+
if (FAILED(hres) && hres != RPC_E_CHANGED_MODE) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Set general COM security levels
|
|
34
|
+
hres = CoInitializeSecurity(
|
|
35
|
+
NULL, -1, NULL, NULL,
|
|
36
|
+
RPC_C_AUTHN_LEVEL_DEFAULT,
|
|
37
|
+
RPC_C_IMP_LEVEL_IMPERSONATE,
|
|
38
|
+
NULL, EOAC_NONE, NULL
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (FAILED(hres) && hres != RPC_E_TOO_LATE) {
|
|
42
|
+
CoUninitialize();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Obtain the initial locator to WMI
|
|
47
|
+
hres = CoCreateInstance(
|
|
48
|
+
CLSID_WbemLocator, 0,
|
|
49
|
+
CLSCTX_INPROC_SERVER,
|
|
50
|
+
IID_IWbemLocator, (LPVOID*)&pLoc
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
if (FAILED(hres)) {
|
|
54
|
+
CoUninitialize();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Connect to WMI
|
|
59
|
+
hres = pLoc->ConnectServer(
|
|
60
|
+
_bstr_t(L"ROOT\\CIMV2"), NULL, NULL, 0,
|
|
61
|
+
NULL, 0, 0, &pSvc
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
if (FAILED(hres)) {
|
|
65
|
+
pLoc->Release();
|
|
66
|
+
CoUninitialize();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Set security levels on the proxy
|
|
71
|
+
hres = CoSetProxyBlanket(
|
|
72
|
+
pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
|
|
73
|
+
RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE,
|
|
74
|
+
NULL, EOAC_NONE
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
if (FAILED(hres)) {
|
|
78
|
+
pSvc->Release();
|
|
79
|
+
pLoc->Release();
|
|
80
|
+
CoUninitialize();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
initialized = true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
~WMIQuery() {
|
|
88
|
+
if (pSvc) pSvc->Release();
|
|
89
|
+
if (pLoc) pLoc->Release();
|
|
90
|
+
CoUninitialize();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
std::string QueryProperty(const wchar_t* wmiClass, const wchar_t* property) {
|
|
94
|
+
if (!initialized) return "";
|
|
95
|
+
|
|
96
|
+
std::wstring query = L"SELECT ";
|
|
97
|
+
query += property;
|
|
98
|
+
query += L" FROM ";
|
|
99
|
+
query += wmiClass;
|
|
100
|
+
|
|
101
|
+
IEnumWbemClassObject* pEnumerator = NULL;
|
|
102
|
+
HRESULT hres = pSvc->ExecQuery(
|
|
103
|
+
bstr_t("WQL"),
|
|
104
|
+
bstr_t(query.c_str()),
|
|
105
|
+
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
|
|
106
|
+
NULL, &pEnumerator
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
if (FAILED(hres)) {
|
|
110
|
+
return "";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
IWbemClassObject* pclsObj = NULL;
|
|
114
|
+
ULONG uReturn = 0;
|
|
115
|
+
std::string result;
|
|
116
|
+
|
|
117
|
+
while (pEnumerator) {
|
|
118
|
+
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
|
|
119
|
+
if (0 == uReturn) {
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
VARIANT vtProp;
|
|
124
|
+
VariantInit(&vtProp);
|
|
125
|
+
hr = pclsObj->Get(property, 0, &vtProp, 0, 0);
|
|
126
|
+
|
|
127
|
+
if (SUCCEEDED(hr)) {
|
|
128
|
+
if (vtProp.vt == VT_BSTR) {
|
|
129
|
+
_bstr_t bstr(vtProp.bstrVal);
|
|
130
|
+
result = (char*)bstr;
|
|
131
|
+
} else if (vtProp.vt == VT_I4 || vtProp.vt == VT_UI4) {
|
|
132
|
+
result = std::to_string(vtProp.lVal);
|
|
133
|
+
} else if (vtProp.vt == VT_I2 || vtProp.vt == VT_UI2) {
|
|
134
|
+
result = std::to_string(vtProp.iVal);
|
|
135
|
+
} else if (vtProp.vt == VT_UI1) {
|
|
136
|
+
result = std::to_string(vtProp.bVal);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
VariantClear(&vtProp);
|
|
141
|
+
pclsObj->Release();
|
|
142
|
+
break; // Get only first result
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
pEnumerator->Release();
|
|
146
|
+
return TrimString(result);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
BiosInfo GetBiosInfo() {
|
|
151
|
+
BiosInfo info;
|
|
152
|
+
WMIQuery wmi;
|
|
153
|
+
|
|
154
|
+
info.vendor = wmi.QueryProperty(L"Win32_BIOS", L"Manufacturer");
|
|
155
|
+
info.version = wmi.QueryProperty(L"Win32_BIOS", L"SMBIOSBIOSVersion");
|
|
156
|
+
info.releaseDate = wmi.QueryProperty(L"Win32_BIOS", L"ReleaseDate");
|
|
157
|
+
info.biosCharacteristics = wmi.QueryProperty(L"Win32_BIOS", L"BIOSVersion");
|
|
158
|
+
|
|
159
|
+
return info;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
SystemInfo GetSystemInfo() {
|
|
163
|
+
SystemInfo info;
|
|
164
|
+
WMIQuery wmi;
|
|
165
|
+
|
|
166
|
+
info.manufacturer = wmi.QueryProperty(L"Win32_ComputerSystem", L"Manufacturer");
|
|
167
|
+
info.productName = wmi.QueryProperty(L"Win32_ComputerSystem", L"Model");
|
|
168
|
+
info.uuid = wmi.QueryProperty(L"Win32_ComputerSystemProduct", L"UUID");
|
|
169
|
+
info.wakeUpType = wmi.QueryProperty(L"Win32_ComputerSystem", L"WakeUpType");
|
|
170
|
+
|
|
171
|
+
// Try to get serial number from ComputerSystemProduct
|
|
172
|
+
std::string serial = wmi.QueryProperty(L"Win32_ComputerSystemProduct", L"IdentifyingNumber");
|
|
173
|
+
if (serial.empty() || serial == "To Be Filled By O.E.M.") {
|
|
174
|
+
serial = wmi.QueryProperty(L"Win32_BIOS", L"SerialNumber");
|
|
175
|
+
}
|
|
176
|
+
info.serialNumber = serial;
|
|
177
|
+
|
|
178
|
+
info.skuNumber = wmi.QueryProperty(L"Win32_ComputerSystemProduct", L"SKUNumber");
|
|
179
|
+
info.family = wmi.QueryProperty(L"Win32_ComputerSystemProduct", L"Version");
|
|
180
|
+
|
|
181
|
+
return info;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
BoardInfo GetBoardInfo() {
|
|
185
|
+
BoardInfo info;
|
|
186
|
+
WMIQuery wmi;
|
|
187
|
+
|
|
188
|
+
info.manufacturer = wmi.QueryProperty(L"Win32_BaseBoard", L"Manufacturer");
|
|
189
|
+
info.product = wmi.QueryProperty(L"Win32_BaseBoard", L"Product");
|
|
190
|
+
info.version = wmi.QueryProperty(L"Win32_BaseBoard", L"Version");
|
|
191
|
+
info.serialNumber = wmi.QueryProperty(L"Win32_BaseBoard", L"SerialNumber");
|
|
192
|
+
info.assetTag = wmi.QueryProperty(L"Win32_BaseBoard", L"Tag");
|
|
193
|
+
info.locationInChassis = wmi.QueryProperty(L"Win32_BaseBoard", L"Model");
|
|
194
|
+
|
|
195
|
+
return info;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
ProcessorInfo GetProcessorInfo() {
|
|
199
|
+
ProcessorInfo info;
|
|
200
|
+
WMIQuery wmi;
|
|
201
|
+
|
|
202
|
+
info.manufacturer = wmi.QueryProperty(L"Win32_Processor", L"Manufacturer");
|
|
203
|
+
info.version = wmi.QueryProperty(L"Win32_Processor", L"Name");
|
|
204
|
+
info.socketDesignation = wmi.QueryProperty(L"Win32_Processor", L"SocketDesignation");
|
|
205
|
+
info.processorType = wmi.QueryProperty(L"Win32_Processor", L"Architecture");
|
|
206
|
+
info.processorFamily = wmi.QueryProperty(L"Win32_Processor", L"Family");
|
|
207
|
+
info.maxSpeed = wmi.QueryProperty(L"Win32_Processor", L"MaxClockSpeed");
|
|
208
|
+
info.currentSpeed = wmi.QueryProperty(L"Win32_Processor", L"CurrentClockSpeed");
|
|
209
|
+
info.coreCount = wmi.QueryProperty(L"Win32_Processor", L"NumberOfCores");
|
|
210
|
+
info.threadCount = wmi.QueryProperty(L"Win32_Processor", L"NumberOfLogicalProcessors");
|
|
211
|
+
info.l2CacheSize = wmi.QueryProperty(L"Win32_Processor", L"L2CacheSize");
|
|
212
|
+
info.l3CacheSize = wmi.QueryProperty(L"Win32_Processor", L"L3CacheSize");
|
|
213
|
+
|
|
214
|
+
return info;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
MemoryInfo GetMemoryInfo() {
|
|
218
|
+
MemoryInfo info;
|
|
219
|
+
WMIQuery wmi;
|
|
220
|
+
|
|
221
|
+
info.totalPhysicalMemory = wmi.QueryProperty(L"Win32_ComputerSystem", L"TotalPhysicalMemory");
|
|
222
|
+
info.maxCapacity = wmi.QueryProperty(L"Win32_PhysicalMemoryArray", L"MaxCapacity");
|
|
223
|
+
info.memoryDevices = wmi.QueryProperty(L"Win32_PhysicalMemoryArray", L"MemoryDevices");
|
|
224
|
+
|
|
225
|
+
// Get available memory from OS
|
|
226
|
+
MEMORYSTATUSEX memStatus;
|
|
227
|
+
memStatus.dwLength = sizeof(memStatus);
|
|
228
|
+
if (GlobalMemoryStatusEx(&memStatus)) {
|
|
229
|
+
info.availablePhysicalMemory = std::to_string(memStatus.ullAvailPhys);
|
|
230
|
+
info.totalVirtualMemory = std::to_string(memStatus.ullTotalVirtual);
|
|
231
|
+
info.availableVirtualMemory = std::to_string(memStatus.ullAvailVirtual);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return info;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
ChassisInfo GetChassisInfo() {
|
|
238
|
+
ChassisInfo info;
|
|
239
|
+
WMIQuery wmi;
|
|
240
|
+
|
|
241
|
+
info.manufacturer = wmi.QueryProperty(L"Win32_SystemEnclosure", L"Manufacturer");
|
|
242
|
+
info.type = wmi.QueryProperty(L"Win32_SystemEnclosure", L"ChassisTypes");
|
|
243
|
+
info.version = wmi.QueryProperty(L"Win32_SystemEnclosure", L"Version");
|
|
244
|
+
info.serialNumber = wmi.QueryProperty(L"Win32_SystemEnclosure", L"SerialNumber");
|
|
245
|
+
info.assetTag = wmi.QueryProperty(L"Win32_SystemEnclosure", L"SMBIOSAssetTag");
|
|
246
|
+
info.bootUpState = wmi.QueryProperty(L"Win32_ComputerSystem", L"BootupState");
|
|
247
|
+
info.powerSupplyState = wmi.QueryProperty(L"Win32_ComputerSystem", L"PowerState");
|
|
248
|
+
info.thermalState = wmi.QueryProperty(L"Win32_ComputerSystem", L"ThermalState");
|
|
249
|
+
|
|
250
|
+
return info;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
} // namespace smbios
|
|
254
|
+
|
|
255
|
+
#endif // _WIN32
|