Well, this is absolutely not clean, but it works as a dirty workaround:
I checks if 'any' screensaver (which have .SCR suffix) is running.
private static boolean isScreensaverRunning() {
List<String> p = WindowsUtils.listRunningProcesses();
for (String s : p) {
if (s.endsWith(".SCR")) {
return true;
}
}
return false;
}
public static List<String> listRunningProcesses() {
List<String> processes = new ArrayList<String>();
try {
String line;
Process p = Runtime.getRuntime().exec("tasklist.exe /fo csv /nh");
BufferedReader input = new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
if (!line.trim().equals("")) {
// keep only the process name
line = line.substring(1);
processes.add(line.substring(0, line.indexOf(""")));
}
}
input.close();
}
catch (Exception err) {
err.printStackTrace();
}
return processes;
}
Source of listRunningProcesses: http://www.rgagnon.com/javadetails/java-0593.html
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…