Host (Windows): detect serial number and UUID

This commit is contained in:
李通洲
2024-01-05 22:44:40 +08:00
parent 6bcd75835e
commit 21f3875c4f
11 changed files with 104 additions and 17 deletions
+1 -1
View File
@@ -13,4 +13,4 @@ typedef struct FFHostResult
FFstrbuf vendor;
} FFHostResult;
const char* ffDetectHost(FFHostResult* host);
const char* ffDetectHost(FFHostResult* host, FFHostOptions* options);
+1 -1
View File
@@ -2,7 +2,7 @@
#include "common/settings.h"
#include <ctype.h>
const char* ffDetectHost(FFHostResult* host)
const char* ffDetectHost(FFHostResult* host, FF_MAYBE_UNUSED FFHostOptions* options)
{
// http://newandroidbook.com/ddb/
ffSettingsGetAndroidProperty("ro.product.device", &host->family);
+1 -1
View File
@@ -201,7 +201,7 @@ const char* getOthersByIokit(FFHostResult* host)
return NULL;
}
const char* ffDetectHost(FFHostResult* host)
const char* ffDetectHost(FFHostResult* host, FF_MAYBE_UNUSED FFHostOptions* options)
{
const char* error = ffSysctlGetString("hw.model", &host->family);
if (error) return error;
+1 -1
View File
@@ -2,7 +2,7 @@
#include "common/settings.h"
#include "util/smbiosHelper.h"
const char* ffDetectHost(FFHostResult* host)
const char* ffDetectHost(FFHostResult* host, FF_MAYBE_UNUSED FFHostOptions* options)
{
ffSettingsGetFreeBSDKenv("smbios.system.product", &host->name);
ffCleanUpSmbiosValue(&host->name);
+1 -1
View File
@@ -27,7 +27,7 @@ static void getHostProductName(FFstrbuf* name)
ffStrbufClear(name);
}
const char* ffDetectHost(FFHostResult* host)
const char* ffDetectHost(FFHostResult* host, FF_MAYBE_UNUSED FFHostOptions* options)
{
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_family", "/sys/class/dmi/id/product_family", &host->family);
getHostProductName(&host->name);
@@ -1,8 +1,30 @@
extern "C"
{
#include "host.h"
#include "util/windows/registry.h"
#include "util/smbiosHelper.h"
}
#include "util/windows/wmi.hpp"
#include "util/windows/unicode.hpp"
const char* ffDetectHost(FFHostResult* host)
const char* detectWithWmi(FFHostResult* host)
{
FFWmiQuery query(L"SELECT IdentifyingNumber, UUID FROM Win32_ComputerSystemProduct", nullptr, FFWmiNamespace::CIMV2);
if(!query)
return "Query WMI service failed";
if (FFWmiRecord record = query.next())
{
if (auto identifyingNumber = record.get(L"IdentifyingNumber"))
ffStrbufSetWSV(&host->serial, identifyingNumber.get<std::wstring_view>());
if (auto uuid = record.get(L"UUID"))
ffStrbufSetWSV(&host->uuid, uuid.get<std::wstring_view>());
return NULL;
}
return "No WMI result returned";
}
const char* ffDetectHost(FFHostResult* host, FFHostOptions* options)
{
FF_HKEY_AUTO_DESTROY hKey = NULL;
@@ -20,5 +42,8 @@ const char* ffDetectHost(FFHostResult* host)
ffRegReadStrbuf(hKey, L"SystemManufacturer", &host->vendor, NULL);
ffCleanUpSmbiosValue(&host->vendor);
if (options->useWmi)
detectWithWmi(host);
return NULL;
}