* @brief Reads the Windows MachineGuid and system UUID, requiring both since a * partial read degrades the fingerprint; the PowerShell UUID query gets a long * timeout so a cold start cannot drop it. */
| 121 | * timeout so a cold start cannot drop it. |
| 122 | */ |
| 123 | static QString readWindowsId(bool& complete) |
| 124 | { |
| 125 | QProcess process; |
| 126 | QString machineGuid, uuid; |
| 127 | |
| 128 | auto systemRoot = qEnvironmentVariable("SystemRoot"); |
| 129 | if (systemRoot.isEmpty()) |
| 130 | systemRoot = QStringLiteral("C:\\Windows"); |
| 131 | |
| 132 | const auto system32 = systemRoot + QStringLiteral("\\System32\\"); |
| 133 | const auto regTool = resolveSystemTool({system32 + "reg.exe"}, "reg"); |
| 134 | |
| 135 | process.start( |
| 136 | regTool, |
| 137 | {"query", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography", "/v", "MachineGuid"}); |
| 138 | awaitTool(process); |
| 139 | QString output = process.readAllStandardOutput(); |
| 140 | QStringList lines = output.split("\n"); |
| 141 | for (const QString& line : std::as_const(lines)) { |
| 142 | if (line.contains("MachineGuid")) { |
| 143 | machineGuid = line.split(" ").last().trimmed(); |
| 144 | break; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | const auto psTool = |
| 149 | resolveSystemTool({system32 + "WindowsPowerShell\\v1.0\\powershell.exe"}, "powershell"); |
| 150 | process.start(psTool, |
| 151 | {"-ExecutionPolicy", |
| 152 | "Bypass", |
| 153 | "-command", |
| 154 | "(Get-CimInstance -Class Win32_ComputerSystemProduct).UUID"}); |
| 155 | awaitTool(process, 30000); |
| 156 | uuid = process.readAllStandardOutput().trimmed(); |
| 157 | |
| 158 | complete = !machineGuid.isEmpty() && !uuid.isEmpty(); |
| 159 | return machineGuid + uuid; |
| 160 | } |
| 161 | #endif |
| 162 | |
| 163 | #if defined(Q_OS_BSD) |
no test coverage detected