mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-22 07:14:15 +08:00
Fix: Use PowerShell to get hadrware info (>=Win7)
This commit is contained in:
@@ -88,9 +88,32 @@ std::string execCommand(const char* cmd)
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string getHardwareID_PS() {
|
||||
// Get-WmiObject <20><> PowerShell 2.0+ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (>=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;
|
||||
}
|
||||
|
||||
// <20><>ȡӲ<C8A1><D3B2> ID<49><44>CPU + <20><><EFBFBD><EFBFBD> + Ӳ<>̣<EFBFBD>
|
||||
std::string getHardwareID(fallback fb)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9> PowerShell <20><><EFBFBD><EFBFBD>
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user