Examples of HKEYByReference


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

      assertEquals(W32Errors.ERROR_FILE_NOT_FOUND, Advapi32.INSTANCE.RegDeleteKey(
          WinReg.HKEY_CURRENT_USER, "JNAAdvapi32TestDoesntExist"));
    }
   
    public void testRegEnumKeyEx() {
      HKEYByReference phKey = new HKEYByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(
          WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
          0, WinNT.KEY_READ, phKey));
      IntByReference lpcSubKeys = new IntByReference();
      IntByReference lpcMaxSubKeyLen = new IntByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryInfoKey(
          phKey.getValue(), null, null, null, lpcSubKeys, lpcMaxSubKeyLen, null, null,
          null, null, null, null));
      char[] name = new char[lpcMaxSubKeyLen.getValue() + 1];
      for (int i = 0; i < lpcSubKeys.getValue(); i++) {
        IntByReference lpcchValueName = new IntByReference(lpcMaxSubKeyLen.getValue() + 1);
          assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegEnumKeyEx(
              phKey.getValue(), i, name, lpcchValueName, null, null, null, null));
          assertEquals(Native.toString(name).length(), lpcchValueName.getValue());
      }
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));           
    }
View Full Code Here

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

      }
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));           
    }
   
    public void testRegEnumValue() {
      HKEYByReference phKey = new HKEYByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(
          WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
          0, WinNT.KEY_READ, phKey));
      IntByReference lpcValues = new IntByReference();
      IntByReference lpcMaxValueNameLen = new IntByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryInfoKey(
          phKey.getValue(), null, null, null, null, null, null, lpcValues,
          lpcMaxValueNameLen, null, null, null));
      char[] name = new char[lpcMaxValueNameLen.getValue() + 1];
      for (int i = 0; i < lpcValues.getValue(); i++) {
        IntByReference lpcchValueName = new IntByReference(lpcMaxValueNameLen.getValue() + 1);
        IntByReference lpType = new IntByReference();
          assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegEnumValue(
              phKey.getValue(), i, name, lpcchValueName, null,
              lpType, null, null));
          assertEquals(Native.toString(name).length(), lpcchValueName.getValue());
      }
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));     
    }
View Full Code Here

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

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

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 {
      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

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 {
      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

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 {
      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

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 {
      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

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

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

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

   * @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
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.