-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: wmic get uuid failed in Windows 11
- Loading branch information
Showing
3 changed files
with
9,490 additions
and
7,320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.