Skip to content

Commit 76fbbb8

Browse files
committed
fix: wmic get uuid failed in Windows 11
1 parent 09b39fa commit 76fbbb8

File tree

3 files changed

+9490
-7320
lines changed

3 files changed

+9490
-7320
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@commitlint/cli": "^13.1.0",
3232
"@commitlint/config-conventional": "^13.1.0",
3333
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.0-rc.6",
34-
"@tauri-apps/cli": "^1.0.0-beta.10",
34+
"@tauri-apps/cli": "1.0.0-beta.10",
3535
"@types/js-yaml": "^4.0.3",
3636
"@types/loadable__component": "^5.13.4",
3737
"@types/lodash-es": "^4.17.5",
@@ -93,7 +93,7 @@
9393
"@sentry/react": "^6.14.1",
9494
"@sentry/tracing": "^6.14.1",
9595
"@shockpkg/plist-dom": "^2.1.1",
96-
"@tauri-apps/api": "^1.0.0-beta.8",
96+
"@tauri-apps/api": "1.0.0-beta.8",
9797
"antd": "^4.16.13",
9898
"axios": "^0.24.0",
9999
"base64-js": "^1.5.1",

src/services/get-wmic-info.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import { execute } from 'utils/execute';
22

33
export async function getWmicInfo() {
4-
const stdout = await execute('cmd.exe', ['/c', 'wmic', 'csproduct', 'get', 'UUID']) as string;
5-
const parsed = stdout ? stdout.split('\n') : [];
6-
if (!parsed.length || parsed.length < 4) {
7-
return {
8-
uuid: null,
9-
};
10-
}
11-
return {
12-
uuid: stdout.split('\n')[2].trim(),
4+
const alternativeCommands = [
5+
['cmd.exe', ['/c', 'wmic', 'csproduct', 'get', 'UUID']],
6+
['powershell.exe', ['Get-WmiObject -Class "Win32_ComputerSystemProduct" | Select-Object -Property UUID']],
7+
];
8+
9+
let result: Record<string, null | string> = {
10+
uuid: null,
11+
};
12+
13+
for (const command of alternativeCommands) {
14+
const [cmd, args] = command;
15+
const stdout = await execute(cmd as string, args as string[]) as string;
16+
const parsed = stdout ? stdout.trim().split('\n') : [];
17+
18+
if (parsed.length) {
19+
result.uuid = parsed[parsed.length - 1].trim();
20+
break;
21+
}
1322
}
23+
24+
return result;
1425
}

0 commit comments

Comments
 (0)