Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/jdiskmark/UtilOs.java
Original file line number Diff line number Diff line change
Expand Up @@ -775,12 +775,41 @@ public static String getProcessorNameWindows() {
LOGGER.log(Level.SEVERE,
"Failed to get processor name. Exit code: {0}", exitCode);
}
} catch (IOException | InterruptedException e) {
} catch (IOException e) {
// wmic may not be available on newer Windows versions (e.g. Windows 11)
LOGGER.log(Level.INFO, "wmic not available, falling back to PowerShell: {0}", e.getMessage());
return getProcessorNameWindowsPowerShell();
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, null, e);
}

return ""; // Return an empty string if no processor name was found
}

static String getProcessorNameWindowsPowerShell() {
try {
ProcessBuilder pb = new ProcessBuilder(
"powershell.exe", "-Command",
"Get-CimInstance -Class Win32_Processor | Select-Object -ExpandProperty Name");
Process process = pb.start();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
if (!line.trim().isEmpty()) {
return line.trim();
}
}
}
int exitCode = process.waitFor();
if (exitCode != 0) {
LOGGER.log(Level.SEVERE,
"Failed to get processor name via PowerShell. Exit code: {0}", exitCode);
}
} catch (IOException | InterruptedException e) {
LOGGER.log(Level.SEVERE, null, e);
}
return "";
}

public static String getProcessorNameMacOS() {
try {
Expand Down