public void registerUninstallKey() throws NativeLibException {
    String uninstallName = getUninstallName();
    if (uninstallName == null) {
      return;
    }
    String keyName = UNINSTALL_ROOT + uninstallName;
    String cmd =
        "\""
            + installdata.getVariable("JAVA_HOME")
            + "\\bin\\javaw.exe\" -jar \""
            + installdata.getVariable("INSTALL_PATH")
            + "\\uninstaller\\uninstaller.jar\"";
    String appVersion = installdata.getVariable("APP_VER");
    String appUrl = installdata.getVariable("APP_URL");

    int oldVal = getRoot();
    try {
      setRoot(HKEY_LOCAL_MACHINE);
      setValue(keyName, "DisplayName", uninstallName);
    } catch (
        NativeLibException
            exception) { // Users without administrative rights should be able to install the app
                         // for themselves
      Debug.trace(
          "Failed to register uninstaller in HKEY_LOCAL_MACHINE hive, trying HKEY_CURRENT_USER: "******"DisplayName", uninstallName);
    }
    setValue(keyName, "UninstallString", cmd);
    setValue(keyName, "DisplayVersion", appVersion);
    if (appUrl != null && appUrl.length() > 0) {
      setValue(keyName, "HelpLink", appUrl);
    }
    // Try to write the uninstaller icon out.
    try {
      InputStream input = ResourceManager.getInstance().getInputStream(UNINSTALLER_ICON);
      String iconPath =
          installdata.getVariable("INSTALL_PATH")
              + File.separator
              + "Uninstaller"
              + File.separator
              + "UninstallerIcon.ico";
      FileOutputStream out = new FileOutputStream(iconPath);
      byte[] buffer = new byte[5120];
      long bytesCopied = 0;
      int bytesInBuffer;
      while ((bytesInBuffer = input.read(buffer)) != -1) {
        out.write(buffer, 0, bytesInBuffer);
        bytesCopied += bytesInBuffer;
      }
      input.close();
      out.close();
      setValue(keyName, "DisplayIcon", iconPath);
    } catch (Exception exception) { // May be no icon resource defined; ignore it
      Debug.trace(exception);
    }
    setRoot(oldVal);
  }
 /**
  * Returns the path to the needed JDK if found in the registry. If there are more than one JDKs
  * registered, that one with the highest allowd version will be returned. Works only on windows.
  * On Unix an empty string returns.
  *
  * @return the path to the needed JDK if found in the windows registry
  */
 private String resolveInRegistry() {
   String retval = "";
   int oldVal = 0;
   RegistryHandler rh = null;
   badRegEntries = new HashSet();
   try {
     // Get the default registry handler.
     rh = RegistryDefaultHandler.getInstance();
     if (rh == null)
       // We are on a os which has no registry or the
       // needed dll was not bound to this installation. In
       // both cases we forget the try to get the JDK path from registry.
       return (retval);
     rh.verify(idata);
     oldVal = rh.getRoot(); // Only for security...
     rh.setRoot(MSWinConstants.HKEY_LOCAL_MACHINE);
     String[] keys = rh.getSubkeys(JDK_ROOT_KEY);
     if (keys == null || keys.length == 0) return (retval);
     Arrays.sort(keys);
     int i = keys.length - 1;
     String min = getMinVersion();
     String max = getMaxVersion();
     // We search for the highest allowd version, therefore retrograde
     while (i > 0) {
       if (compareVersions(
           keys[i],
           max,
           false,
           4,
           4,
           "__NO_NOT_IDENTIFIER_")) { // First allowd version found, now we have to test that the
                                      // min value
         // also allows this version.
         if (compareVersions(keys[i], min, true, 4, 4, "__NO_NOT_IDENTIFIER_")) {
           String cv = JDK_ROOT_KEY + "\\" + keys[i];
           String path = rh.getValue(cv, JDK_VALUE_NAME).getStringData();
           // Use it only if the path is valid.
           // Set the path for method pathIsValid ...
           pathSelectionPanel.setPath(path);
           if (!pathIsValid()) {
             badRegEntries.add(keys[i]);
           } else if ("".equals(retval)) {
             retval = path;
           }
           pathSelectionPanel.setPath(retval);
         }
       }
       i--;
     }
   } catch (Exception e) { // Will only be happen if registry handler is good, but an
     // exception at performing was thrown. This is an error...
     e.printStackTrace();
   } finally {
     if (rh != null && oldVal != 0)
       try {
         rh.setRoot(MSWinConstants.HKEY_LOCAL_MACHINE);
       } catch (NativeLibException e) {
         e.printStackTrace();
       }
   }
   return (retval);
 }