Examples of HKEYByReference


Examples of com.sun.jna.examples.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

     * Gets the all com info on system.
     *
     * @return the all com info on system
     */
    public static ArrayList<COMInfo> getAllCOMInfoOnSystem() {
        HKEYByReference phkResult = new HKEYByReference();
        HKEYByReference phkResult2 = new HKEYByReference();
        String subKey;
        ArrayList<COMInfo> comInfos = new ArrayList<COMUtils.COMInfo>();

        try {
            // open root key
            phkResult = Advapi32Util.registryGetKey(WinReg.HKEY_CLASSES_ROOT,
                    "CLSID", WinNT.KEY_ALL_ACCESS);
            // open subkey
            InfoKey infoKey = Advapi32Util.registryQueryInfoKey(
                    phkResult.getValue(), WinNT.KEY_ALL_ACCESS);

            for (int i = 0; i < infoKey.lpcSubKeys.getValue(); i++) {
                EnumKey enumKey = Advapi32Util.registryRegEnumKey(
                        phkResult.getValue(), i);
                subKey = Native.toString(enumKey.lpName);

                COMInfo comInfo = new COMInfo(subKey);

                phkResult2 = Advapi32Util.registryGetKey(phkResult.getValue(),
                        subKey, WinNT.KEY_ALL_ACCESS);
                InfoKey infoKey2 = Advapi32Util.registryQueryInfoKey(
                        phkResult2.getValue(), WinNT.KEY_ALL_ACCESS);

                for (int y = 0; y < infoKey2.lpcSubKeys.getValue(); y++) {
                    EnumKey enumKey2 = Advapi32Util.registryRegEnumKey(
                            phkResult2.getValue(), y);
                    String subKey2 = Native.toString(enumKey2.lpName);

                    if (subKey2.equals("InprocHandler32")) {
                        comInfo.inprocHandler32 = (String) Advapi32Util
                                .registryGetValue(phkResult2.getValue(),
                                        subKey2, null);
                    } else if (subKey2.equals("InprocServer32")) {
                        comInfo.inprocServer32 = (String) Advapi32Util
                                .registryGetValue(phkResult2.getValue(),
                                        subKey2, null);
                    } else if (subKey2.equals("LocalServer32")) {
                        comInfo.localServer32 = (String) Advapi32Util
                                .registryGetValue(phkResult2.getValue(),
                                        subKey2, null);
                    } else if (subKey2.equals("ProgID")) {
                        comInfo.progID = (String) Advapi32Util
                                .registryGetValue(phkResult2.getValue(),
                                        subKey2, null);
                    } else if (subKey2.equals("TypeLib")) {
                        comInfo.typeLib = (String) Advapi32Util
                                .registryGetValue(phkResult2.getValue(),
                                        subKey2, null);
                    }
                }

                Advapi32.INSTANCE.RegCloseKey(phkResult2.getValue());
                comInfos.add(comInfo);
            }
        } finally {
            Advapi32.INSTANCE.RegCloseKey(phkResult.getValue());
            Advapi32.INSTANCE.RegCloseKey(phkResult2.getValue());
        }

        return comInfos;
    }
View Full Code Here

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

     * Gets the all com info on system.
     *
     * @return the all com info on system
     */
    public static ArrayList<COMInfo> getAllCOMInfoOnSystem() {
        HKEYByReference phkResult = new HKEYByReference();
        HKEYByReference phkResult2 = new HKEYByReference();
        String subKey;
        ArrayList<COMInfo> comInfos = new ArrayList<COMUtils.COMInfo>();

        try {
            // open root key
            phkResult = Advapi32Util.registryGetKey(WinReg.HKEY_CLASSES_ROOT,
                    "CLSID", WinNT.KEY_READ);
            // open subkey
            InfoKey infoKey = Advapi32Util.registryQueryInfoKey(
                    phkResult.getValue(), WinNT.KEY_READ);

            for (int i = 0; i < infoKey.lpcSubKeys.getValue(); i++) {
                EnumKey enumKey = Advapi32Util.registryRegEnumKey(
                        phkResult.getValue(), i);
                subKey = Native.toString(enumKey.lpName);

                COMInfo comInfo = new COMInfo(subKey);

                phkResult2 = Advapi32Util.registryGetKey(phkResult.getValue(),
                        subKey, WinNT.KEY_READ);
                InfoKey infoKey2 = Advapi32Util.registryQueryInfoKey(
                        phkResult2.getValue(), WinNT.KEY_READ);

                for (int y = 0; y < infoKey2.lpcSubKeys.getValue(); y++) {
                    EnumKey enumKey2 = Advapi32Util.registryRegEnumKey(
                            phkResult2.getValue(), y);
                    String subKey2 = Native.toString(enumKey2.lpName);

                    if (subKey2.equals("InprocHandler32")) {
                        comInfo.inprocHandler32 = (String) Advapi32Util
                                .registryGetValue(phkResult2.getValue(),
                                        subKey2, null);
                    } else if (subKey2.equals("InprocServer32")) {
                        comInfo.inprocServer32 = (String) Advapi32Util
                                .registryGetValue(phkResult2.getValue(),
                                        subKey2, null);
                    } else if (subKey2.equals("LocalServer32")) {
                        comInfo.localServer32 = (String) Advapi32Util
                                .registryGetValue(phkResult2.getValue(),
                                        subKey2, null);
                    } else if (subKey2.equals("ProgID")) {
                        comInfo.progID = (String) Advapi32Util
                                .registryGetValue(phkResult2.getValue(),
                                        subKey2, null);
                    } else if (subKey2.equals("TypeLib")) {
                        comInfo.typeLib = (String) Advapi32Util
                                .registryGetValue(phkResult2.getValue(),
                                        subKey2, null);
                    }
                }

                Advapi32.INSTANCE.RegCloseKey(phkResult2.getValue());
                comInfos.add(comInfo);
            }
        } finally {
            Advapi32.INSTANCE.RegCloseKey(phkResult.getValue());
            Advapi32.INSTANCE.RegCloseKey(phkResult2.getValue());
        }

        return comInfos;
    }
View Full Code Here

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

 
    public void testRegistryGetCloseKey() {
        Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
        Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key1");
        Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key2");
        HKEYByReference phkKey = Advapi32Util.registryGetKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", WinNT.KEY_READ);
        String[] subKeys = Advapi32Util.registryGetKeys(phkKey.getValue());
        assertEquals(2, subKeys.length);
        assertEquals(subKeys[0], "Key1");
        assertEquals(subKeys[1], "Key2");
        Advapi32Util.registryCloseKey(phkKey.getValue());
        Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key1");
        Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key2");
        Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
    }
View Full Code Here

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

        assertEquals(1, values.size());
        assertTrue(values.containsKey(valueName));
    }

    private static void registrySetEmptyValue(HKEY root, String keyPath, String name, final int valueType) {
        HKEYByReference phkKey = new HKEYByReference();
        int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
        if (rc != W32Errors.ERROR_SUCCESS) {
            throw new Win32Exception(rc);
        }
        try {
            char[] data = new char[0];
            rc = Advapi32.INSTANCE.RegSetValueEx(phkKey.getValue(), name, 0, valueType, data, 0);
            if (rc != W32Errors.ERROR_SUCCESS) {
                throw new Win32Exception(rc);
            }
        } 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

            null, userInfo.usri1_name.toString()));     
    }
    }
   
    public void testRegOpenKeyEx() {
      HKEYByReference phKey = new HKEYByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(
          WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft", 0, WinNT.KEY_READ, phKey));
      assertTrue(WinBase.INVALID_HANDLE_VALUE != phKey.getValue());
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));     
    }
View Full Code Here

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

      assertTrue(WinBase.INVALID_HANDLE_VALUE != phKey.getValue());
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));     
    }
   
    public void testRegQueryValueEx() {
      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 lpcbData = new IntByReference();
      IntByReference lpType = new IntByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(
          phKey.getValue(), "User Agent", 0, lpType, (char[]) null, lpcbData));
      assertEquals(WinNT.REG_SZ, lpType.getValue());
      assertTrue(lpcbData.getValue() > 0);
      char[] buffer = new char[lpcbData.getValue()];
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(
          phKey.getValue(), "User Agent", 0, lpType, buffer, lpcbData));
      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_FILE_NOT_FOUND, Advapi32.INSTANCE.RegDeleteValue(
          WinReg.HKEY_CURRENT_USER, "JNAAdvapi32TestDoesntExist"));
    }
   
    public void testRegSetValueEx_REG_SZ() {
      HKEYByReference phKey = new HKEYByReference();
      // create parent key
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(
          WinReg.HKEY_CURRENT_USER, "Software", 0, WinNT.KEY_WRITE | WinNT.KEY_READ, phKey));
      HKEYByReference phkTest = new HKEYByReference();
      IntByReference lpdwDisposition = new IntByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCreateKeyEx(
          phKey.getValue(), "JNAAdvapi32Test", 0, null, 0, WinNT.KEY_ALL_ACCESS,
          null, phkTest, lpdwDisposition));
      // write a REG_SZ value
      char[] lpData = Native.toCharArray("Test");
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegSetValueEx(
          phkTest.getValue(), "REG_SZ", 0, WinNT.REG_SZ, lpData, lpData.length * 2));
      // re-read the REG_SZ value
      IntByReference lpType = new IntByReference();
      IntByReference lpcbData = new IntByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(
          phkTest.getValue(), "REG_SZ", 0, lpType, (char[]) null, lpcbData));
      assertEquals(WinNT.REG_SZ, lpType.getValue());
      assertTrue(lpcbData.getValue() > 0);
      char[] buffer = new char[lpcbData.getValue()];
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(
          phkTest.getValue(), "REG_SZ", 0, lpType, buffer, lpcbData));
      assertEquals("Test", Native.toString(buffer));
      // delete the test key
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(
          phkTest.getValue()));                 
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegDeleteKey(
          phKey.getValue(), "JNAAdvapi32Test"));
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));                 
    }
View Full Code Here

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

          phKey.getValue(), "JNAAdvapi32Test"));
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));                 
    }
   
    public void testRegSetValueEx_DWORD() {
      HKEYByReference phKey = new HKEYByReference();
      // create parent key
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(
          WinReg.HKEY_CURRENT_USER, "Software", 0, WinNT.KEY_WRITE | WinNT.KEY_READ, phKey));
      HKEYByReference phkTest = new HKEYByReference();
      IntByReference lpdwDisposition = new IntByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCreateKeyEx(
          phKey.getValue(), "JNAAdvapi32Test", 0, null, 0, WinNT.KEY_ALL_ACCESS,
          null, phkTest, lpdwDisposition));
      // write a REG_DWORD value
      int value = 42145;
        byte[] data = new byte[4];
        data[0] = (byte)(value & 0xff);
        data[1] = (byte)((value >> 8) & 0xff);
        data[2] = (byte)((value >> 16) & 0xff);
        data[3] = (byte)((value >> 24) & 0xff);
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegSetValueEx(
          phkTest.getValue(), "DWORD", 0, WinNT.REG_DWORD, data, 4));     
      // re-read the REG_DWORD value
      IntByReference lpType = new IntByReference();
      IntByReference lpcbData = new IntByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(
          phkTest.getValue(), "DWORD", 0, lpType, (char[]) null, lpcbData));
      assertEquals(WinNT.REG_DWORD, lpType.getValue());
      assertEquals(4, lpcbData.getValue());
      IntByReference valueRead = new IntByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(
          phkTest.getValue(), "DWORD", 0, lpType, valueRead, lpcbData));
      assertEquals(value, valueRead.getValue());
      // delete the test key
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(
          phkTest.getValue()));                 
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegDeleteKey(
          phKey.getValue(), "JNAAdvapi32Test"));
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));                 
    }
View Full Code Here

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

          phKey.getValue(), "JNAAdvapi32Test"));
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));                 
    }
   
    public void testRegCreateKeyEx() {
      HKEYByReference phKey = new HKEYByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(
          WinReg.HKEY_CURRENT_USER, "Software", 0, WinNT.KEY_WRITE | WinNT.KEY_READ, phKey));
      HKEYByReference phkResult = new HKEYByReference();
      IntByReference lpdwDisposition = new IntByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCreateKeyEx(
          phKey.getValue(), "JNAAdvapi32Test", 0, null, 0, WinNT.KEY_ALL_ACCESS,
          null, phkResult, lpdwDisposition));
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phkResult.getValue()));                 
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegDeleteKey(
          phKey.getValue(), "JNAAdvapi32Test"));
      assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));           
    }
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.