Пример #1
0
  /** Determine whether the current user has Windows administrator privileges. */
  public static boolean isWinAdmin() {
    if (!isWinPlatform()) return false;
    //    for (String group : new com.sun.security.auth.module.NTSystem().getGroupIDs()) {
    //      if (group.equals("S-1-5-32-544")) return true; // "S-1-5-32-544" is a well-known
    // security identifier in Windows. If the current user has it then he/she/it is an
    // administrator.
    //    }
    //    return false;

    try {
      Class<?> ntsys = Class.forName("com.sun.security.auth.module.NTSystem");
      if (ntsys != null) {
        Object groupObj =
            SystemUtils.invoke(
                ntsys.newInstance(), ntsys.getDeclaredMethod("getGroupIDs"), (Object[]) null);
        if (groupObj instanceof String[]) {
          for (String group : (String[]) groupObj) {
            if (group.equals("S-1-5-32-544"))
              return true; // "S-1-5-32-544" is a well-known security identifier in Windows. If the
                           // current user has it then he/she/it is an administrator.
          }
        }
      }
    } catch (ReflectiveOperationException e) {
      System.err.println(e);
    }
    return false;
  }
Пример #2
0
 public static Frame getSharedOwnerFrame() {
   try {
     Method getSharedOwnerFrame =
         SwingUtilities.class.getDeclaredMethod("getSharedOwnerFrame"); // package-protected
     Object frame =
         SystemUtils.invoke(
             null,
             getSharedOwnerFrame); // getSharedOwnerFrame() is static - invoke it on null object
     return (frame instanceof Frame) ? (Frame) frame : null;
   } catch (NoSuchMethodException | SecurityException e) {
     e.printStackTrace();
   }
   return null;
 }