-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
32 lines (28 loc) · 903 Bytes
/
Main.java
File metadata and controls
32 lines (28 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.io.PrintStream;
import java.util.prefs.Preferences;
/**
*
* @author SoftwareOrgMX
*/
public class Main {
public static void main(String[] args) {
System.out.println("Is Admin: " + isAdmin());
}
public static boolean isAdmin() {
Preferences prefs = Preferences.systemRoot();
PrintStream systemErr = System.err;
synchronized (systemErr) { // better synchroize to avoid problems with other threads that access System.err
System.setErr(null);
try {
prefs.put("foo", "bar"); // SecurityException on Windows
prefs.remove("foo");
prefs.flush(); // BackingStoreException on Linux
return true;
} catch (Exception e) {
return false;
} finally {
System.setErr(systemErr);
}
}
}
}