Last active
December 20, 2015 02:49
-
-
Save tomhermann/6059666 to your computer and use it in GitHub Desktop.
Writing a baby android app to lock my computer remotely, I'm sure this has its issues, but works on my machine :)
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
package com.zombietank; | |
import java.io.IOException; | |
public class SystemControl { | |
public boolean lockComputer() { | |
return executeAndWait("rundll32.exe", "user32.dll,LockWorkStation"); | |
} | |
private boolean executeAndWait(String... commands) { | |
try { | |
Process process = execute(commands); | |
process.waitFor(); | |
return process.exitValue() == 0; | |
} catch (IOException | InterruptedException e) { | |
return false; | |
} | |
} | |
private Process execute(String... commands) throws IOException { | |
ProcessBuilder processBuilder = new ProcessBuilder(commands); | |
return processBuilder.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment