可以确定操作系统用户是否是使用小程序的管理员(在Java小程序中)?怎样
我需要确定用户是否具有管理员权限,主要针对Windows,但我也会获得Linux和OSX的这些信息。
我知道我可以通过"System.getProperty("XXX")"获得一些信息,但没有发现用户是否是系统管理员。
我通过Javascript(操作系统、浏览器等)获得的其他信息
提前感谢。
不是我想要的解决方案(跨平台),我相信它会更好。。。但大多数情况下都是解决方案。
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();
}
}
欢迎任何更好的解决方案!