0

It is possible to determine if the OS user is administrator using Applets (inside a Java Applet)? How?

I need to determine whether or not the user has administrator rights, primarily for Windows but I would also get this information for Linux and OSX.

I know I can get some information via "System.getProperty (" XXX ")", but found nothing as to whether or not the user is a system administrator.

Others informations I am get via Javascript (OS, Browser and etc.)

Thanks in Advance.

  • Referring to this post, because you did not bother searching. Although I do believe you were looking for other systems as well. I did however find the Windows relevant post for you. [HERE.](http://stackoverflow.com/questions/4350356/detect-if-java-application-was-run-as-a-windows-admin) You will also find other relevant answers in that post. – iWumbo Dec 11 '13 at 16:57
  • Hi iWumbo, I bothered to perform the search (not just once) included in google ... But you thought correctly, I did the search (and looking) for a generic solution for the systems described. Initially I thought it could be a similar solution as System.getProperty ("x"). The solution (link) you gave me I already knew, as well as other links with the same or similar code, but not discarded the possibility that people who know more than me about Java (java is not my primary language) could be another solution included the generic or similar for other OS. Anyway thanks! – Pablo Ernesto Vigneaux Wilton Dec 13 '13 at 15:08

1 Answers1

0

Not the solution I was looking for (cross plataform), I believe it could be better ... but the solution for most cases.

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();
    }
}

Any better solution is welcome!