Examples of HKEYByReference


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

   * @param keyPath
   *            Path to a registry key.
   * @return Array of registry key names.
   */
  public static String[] registryGetKeys(HKEY root, String keyPath) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0,
        WinNT.KEY_READ, phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
      throw new Win32Exception(rc);
    }
    try {
      return registryGetKeys(phkKey.getValue());
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here

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

   *
   * @return HKEYByReference.
   */
  public static HKEYByReference registryGetKey(HKEY root, String keyPath,
      int samDesired) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, samDesired,
        phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
      throw new Win32Exception(rc);
    }
View Full Code Here

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

   *            Regitry key path.
   * @return Table of values.
   */
  public static TreeMap<String, Object> registryGetValues(HKEY root,
      String keyPath) {
    HKEYByReference phkKey = new HKEYByReference();
    int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0,
        WinNT.KEY_READ, phkKey);
    if (rc != W32Errors.ERROR_SUCCESS) {
      throw new Win32Exception(rc);
    }
    try {
      return registryGetValues(phkKey.getValue());
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here

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

   *  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

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

   *  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_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

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

   *  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 {
      IntByReference lpcbData = new IntByReference();
      IntByReference lpType = new IntByReference();
      rc = Advapi32.INSTANCE.RegQueryValueEx(
          phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData);
      if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(rc);
      }
      if (lpType.getValue() != WinNT.REG_SZ) {
        throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_SZ");
      }
      char[] data = new char[lpcbData.getValue()];
      rc = Advapi32.INSTANCE.RegQueryValueEx(
          phkKey.getValue(), value, 0, lpType, data, lpcbData);
      if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(rc);
      }
      return Native.toString(data);
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here

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

   *  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 {
      IntByReference lpcbData = new IntByReference();
      IntByReference lpType = new IntByReference();
      rc = Advapi32.INSTANCE.RegQueryValueEx(
          phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData);
      if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(rc);
      }
      if (lpType.getValue() != WinNT.REG_EXPAND_SZ) {
        throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_SZ");
      }
      char[] data = new char[lpcbData.getValue()];
      rc = Advapi32.INSTANCE.RegQueryValueEx(
          phkKey.getValue(), value, 0, lpType, data, lpcbData);
      if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(rc);
      }
      return Native.toString(data);
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here

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

   *  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 {
      IntByReference lpcbData = new IntByReference();
      IntByReference lpType = new IntByReference();
      rc = Advapi32.INSTANCE.RegQueryValueEx(
          phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData);
      if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(rc);
      }
      if (lpType.getValue() != WinNT.REG_MULTI_SZ) {
        throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_SZ");
      }
      Memory data = new Memory(lpcbData.getValue());
      rc = Advapi32.INSTANCE.RegQueryValueEx(
          phkKey.getValue(), value, 0, lpType, data, lpcbData);
      if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(rc);
      }
      ArrayList<String> result = new ArrayList<String>();
      int offset = 0;
      while(offset < data.size()) {
        String s = data.getString(offset, true);
        offset += s.length() * Native.WCHAR_SIZE;
        offset += Native.WCHAR_SIZE;
        result.add(s);
      }
      return result.toArray(new String[0]);
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here

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

   *  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 {
      IntByReference lpcbData = new IntByReference();
      IntByReference lpType = new IntByReference();
      rc = Advapi32.INSTANCE.RegQueryValueEx(
          phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData);
      if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(rc);
      }
      if (lpType.getValue() != WinNT.REG_BINARY) {
        throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_BINARY");
      }
      byte[] data = new byte[lpcbData.getValue()];
      rc = Advapi32.INSTANCE.RegQueryValueEx(
          phkKey.getValue(), value, 0, lpType, data, lpcbData);
      if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(rc);
      }
      return data;
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here

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

   *  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 {
      IntByReference lpcbData = new IntByReference();
      IntByReference lpType = new IntByReference();
      rc = Advapi32.INSTANCE.RegQueryValueEx(
          phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData);
      if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(rc);
      }
      if (lpType.getValue() != WinNT.REG_DWORD) {
        throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_SZ");
      }
      IntByReference data = new IntByReference();
      rc = Advapi32.INSTANCE.RegQueryValueEx(
          phkKey.getValue(), value, 0, lpType, data, lpcbData);
      if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
        throw new Win32Exception(rc);
      }
      return data.getValue();
    } finally {
      rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
      if (rc != W32Errors.ERROR_SUCCESS) {
        throw new Win32Exception(rc);
      }
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.