Skip to content

Commit

Permalink
fix: wmic get uuid failed in Windows 11
Browse files Browse the repository at this point in the history
  • Loading branch information
kirainmoe committed Mar 1, 2022
1 parent 09b39fa commit 76fbbb8
Show file tree
Hide file tree
Showing 3 changed files with 9,490 additions and 7,320 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.0-rc.6",
"@tauri-apps/cli": "^1.0.0-beta.10",
"@tauri-apps/cli": "1.0.0-beta.10",
"@types/js-yaml": "^4.0.3",
"@types/loadable__component": "^5.13.4",
"@types/lodash-es": "^4.17.5",
Expand Down Expand Up @@ -93,7 +93,7 @@
"@sentry/react": "^6.14.1",
"@sentry/tracing": "^6.14.1",
"@shockpkg/plist-dom": "^2.1.1",
"@tauri-apps/api": "^1.0.0-beta.8",
"@tauri-apps/api": "1.0.0-beta.8",
"antd": "^4.16.13",
"axios": "^0.24.0",
"base64-js": "^1.5.1",
Expand Down
29 changes: 20 additions & 9 deletions src/services/get-wmic-info.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import { execute } from 'utils/execute';

export async function getWmicInfo() {
const stdout = await execute('cmd.exe', ['/c', 'wmic', 'csproduct', 'get', 'UUID']) as string;
const parsed = stdout ? stdout.split('\n') : [];
if (!parsed.length || parsed.length < 4) {
return {
uuid: null,
};
}
return {
uuid: stdout.split('\n')[2].trim(),
const alternativeCommands = [
['cmd.exe', ['/c', 'wmic', 'csproduct', 'get', 'UUID']],
['powershell.exe', ['Get-WmiObject -Class "Win32_ComputerSystemProduct" | Select-Object -Property UUID']],
];

let result: Record<string, null | string> = {
uuid: null,
};

for (const command of alternativeCommands) {
const [cmd, args] = command;
const stdout = await execute(cmd as string, args as string[]) as string;
const parsed = stdout ? stdout.trim().split('\n') : [];

if (parsed.length) {
result.uuid = parsed[parsed.length - 1].trim();
break;
}
}

return result;
}
Loading

0 comments on commit 76fbbb8

Please sign in to comment.