不是我正在尋找的解決方案(交叉平臺),我相信它可能會更好......但是對於大多數情況而言,這是一種解決方案。
private static boolean isAdminWin()
{
String groups[] = (new com.sun.security.auth.module.NTSystem()).getGroupIDs();
for (String group : groups) {
if (group.equals("S-1-5-32-544"))
return true;
}
return false;
}
public static String getOSName()
{
return System.getProperty("os.name");
}
private static boolean isAdminLinux()
{
return getUserName.equalsIgnoreCase("root");
}
public static boolean isAdmin()
{
if (getOSName().toUpperCase().startsWith("WINDOWS")){
return isAdminWin();
} else {
return isAdminLinux();
}
}
歡迎任何更好的解決方案!
參考這篇文章,因爲你沒有打擾搜索。雖然我確實相信你也在尋找其他系統。然而,我確實爲你找到了Windows相關的文章。 [這裏。](http://stackoverflow.com/questions/4350356/detect-if-java-application-was-run-as-a-windows-admin)您還可以在該帖子中找到其他相關答案。 – iWumbo
嗨iWumbo, 我困擾於執行谷歌搜索(不只是一次)......但你認爲是正確的,我做了搜索(和尋找)爲所描述的系統的通用解決方案。最初我以爲它可能是一個類似System.getProperty(「x」)的解決方案。你給我的解決方案(鏈接)我已經知道了,以及其他具有相同或相似代碼的鏈接,但並沒有拋棄比我更瞭解Java(java不是我的主要語言)的人可能是另一種解決方案的可能性包括其他操作系統的通用或類似的。不管怎樣,謝謝! –