From bddd69a0bdf0e0edabd67c24cef2d9a1c6a69573 Mon Sep 17 00:00:00 2001
From: yuanyuanxiang <962914132@qq.com>
Date: Sat, 20 Dec 2025 11:43:39 +0100
Subject: [PATCH] Fix: Use PowerShell to get hadrware info (>=Win7)
---
.../2015Remote/2015Remote_vs2015.vcxproj.user | 1 +
server/2015Remote/pwd_gen.cpp | 23 +++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/server/2015Remote/2015Remote_vs2015.vcxproj.user b/server/2015Remote/2015Remote_vs2015.vcxproj.user
index ef96aac..2f18391 100644
--- a/server/2015Remote/2015Remote_vs2015.vcxproj.user
+++ b/server/2015Remote/2015Remote_vs2015.vcxproj.user
@@ -4,6 +4,7 @@
$(SolutionDir)Bin\$(TargetName)_x86d$(TargetExt)
WindowsLocalDebugger
-agent
+ -agent|
$(SolutionDir)Bin\$(TargetName)_x86$(TargetExt)
diff --git a/server/2015Remote/pwd_gen.cpp b/server/2015Remote/pwd_gen.cpp
index 8e15bbf..ec4820f 100644
--- a/server/2015Remote/pwd_gen.cpp
+++ b/server/2015Remote/pwd_gen.cpp
@@ -88,9 +88,32 @@ std::string execCommand(const char* cmd)
return result;
}
+std::string getHardwareID_PS() {
+ // Get-WmiObject 在 PowerShell 2.0+ 都可用 (>=Win7)
+ const char* psScript =
+ "(Get-WmiObject Win32_Processor).ProcessorId + '|' + "
+ "(Get-WmiObject Win32_BaseBoard).SerialNumber + '|' + "
+ "(Get-WmiObject Win32_DiskDrive | Select -First 1).SerialNumber";
+
+ std::string cmd = "powershell -NoProfile -Command \"";
+ cmd += psScript;
+ cmd += "\"";
+
+ std::string combinedID = execCommand(cmd.c_str());
+ if ((combinedID.empty() || combinedID.find("ERROR") != std::string::npos)) {
+ return "";
+ }
+ return combinedID;
+}
+
// 获取硬件 ID(CPU + 主板 + 硬盘)
std::string getHardwareID(fallback fb)
{
+ // 优先使用 PowerShell 方法
+ std::string psID = getHardwareID_PS();
+ if (!psID.empty()) {
+ return psID;
+ }
std::string cpuID = execCommand("wmic cpu get processorid");
std::string boardID = execCommand("wmic baseboard get serialnumber");
std::string diskID = execCommand("wmic diskdrive get serialnumber");