Package com.sun.jna.platform.win32.WinReg

Examples of com.sun.jna.platform.win32.WinReg.HKEYByReference


   * @param key
   *            Path to the registry key.
   * @return True if the key exists.
   */
  public static boolean registryKeyExists(HKEY root, String key) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ,
        phkKey);
    switch (rc) {
    case W32Errors.ERROR_SUCCESS:
      Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      return true;
    case W32Errors.ERROR_FILE_NOT_FOUND:
      return false;
    default:
      throw new Win32Exception(rc);
View Full Code Here


   *            Value name.
   * @return True if the value exists.
   */
  public static boolean registryValueExists(HKEY root, String key,
      String value) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ,
        phkKey);
    try {
      switch (rc) {
      case W32Errors.ERROR_SUCCESS:
        break;
      case W32Errors.ERROR_FILE_NOT_FOUND:
        return false;
      default:
        throw new Win32Exception(rc);
      }
      IntByReference lpcbData = new IntByReference();
      IntByReference lpType = new IntByReference();
      rc = Advapi32.INSTANCE.RegQueryValueEx(phkKey.getValue(), value, 0,
          lpType, (char[]) null, lpcbData);
      switch (rc) {
      case W32Errors.ERROR_SUCCESS:
      case W32Errors.ERROR_MORE_DATA:
      case W32Errors.ERROR_INSUFFICIENT_BUFFER:
        return true;
      case W32Errors.ERROR_FILE_NOT_FOUND:
        return false;
      default:
        throw new Win32Exception(rc);
      }
    } finally {
      if (phkKey.getValue() != WinBase.INVALID_HANDLE_VALUE) {
        rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
        if (rc != W32Errors.ERROR_SUCCESS) {
          throw new Win32Exception(rc);
        }
      }
    }
View Full Code Here

   *            Name of the value to retrieve.
   * @return String value.
   */
  public static String registryGetStringValue(HKEY root, String key,
      String value) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ,
        phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
      throw new Win32Exception(rc);
    }
    try {
      return registryGetStringValue(phkKey.getValue(), value);
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here

   *            Name of the value to retrieve.
   * @return String value.
   */
  public static String registryGetExpandableStringValue(HKEY root,
      String key, String value) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ,
        phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
      throw new Win32Exception(rc);
    }
    try {
      return registryGetExpandableStringValue(phkKey.getValue(), value);
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here

   *            Name of the value to retrieve.
   * @return String value.
   */
  public static String[] registryGetStringArray(HKEY root, String key,
      String value) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ,
        phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
      throw new Win32Exception(rc);
    }
    try {
      return registryGetStringArray(phkKey.getValue(), value);
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here

   *            Name of the value to retrieve.
   * @return String value.
   */
  public static byte[] registryGetBinaryValue(HKEY root, String key,
      String value) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ,
        phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
      throw new Win32Exception(rc);
    }
    try {
      return registryGetBinaryValue(phkKey.getValue(), value);
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here

   * @param value
   *            Name of the value to retrieve.
   * @return Integer value.
   */
  public static int registryGetIntValue(HKEY root, String key, String value) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ,
        phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
      throw new Win32Exception(rc);
    }
    try {
      return registryGetIntValue(phkKey.getValue(), value);
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here

   * @param value
   *            Name of the value to retrieve.
   * @return Integer value.
   */
  public static long registryGetLongValue(HKEY root, String key, String value) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ,
        phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
      throw new Win32Exception(rc);
    }
    try {
      return registryGetLongValue(phkKey.getValue(), value);
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here

   * @param keyName
   *            Key name.
   * @return True if the key was created, false otherwise.
   */
  public static boolean registryCreateKey(HKEY hKey, String keyName) {
    HKEYByReference phkResult = new HKEYByReference();
    IntByReference lpdwDisposition = new IntByReference();
    int rc = Advapi32.INSTANCE.RegCreateKeyEx(hKey, keyName, 0, null,
        WinNT.REG_OPTION_NON_VOLATILE, WinNT.KEY_READ, null, phkResult,
        lpdwDisposition);
    if (rc != W32Errors.ERROR_SUCCESS) {
      throw new Win32Exception(rc);
    }
    rc = Advapi32.INSTANCE.RegCloseKey(phkResult.getValue());
    if (rc != W32Errors.ERROR_SUCCESS) {
      throw new Win32Exception(rc);
    }
    return WinNT.REG_CREATED_NEW_KEY == lpdwDisposition.getValue();
  }
View Full Code Here

   *            Key name.
   * @return True if the key was created, false otherwise.
   */
  public static boolean registryCreateKey(HKEY root, String parentPath,
      String keyName) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, parentPath, 0,
        WinNT.KEY_CREATE_SUB_KEY, phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
      throw new Win32Exception(rc);
    }
    try {
      return registryCreateKey(phkKey.getValue(), keyName);
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.sun.jna.platform.win32.WinReg.HKEYByReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.