public void dispose() { if(handle!=0) Advapi32.INSTANCE.RegCloseKey(handle); handle = 0; }
/** * Deletes this key (and disposes the key.) */ public void delete() { check(Advapi32.INSTANCE.RegDeleteKey(handle, path)); dispose(); }
public void deleteValue(String valueName) { check(Advapi32.INSTANCE.RegDeleteValue(handle, valueName)); }
/** * Writes a DWORD value. */ public void setValue(String name, int value) { 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); check(Advapi32.INSTANCE.RegSetValueEx(handle, name, 0, WINNT.REG_DWORD, data, data.length)); }
private byte[] getValue(String valueName) { IntByReference pType, lpcbData; byte[] lpData = new byte[1]; pType = new IntByReference(); lpcbData = new IntByReference(); OUTER: while(true) { int r = Advapi32.INSTANCE.RegQueryValueEx(handle, valueName, null, pType, lpData, lpcbData); switch (r) { case WINERROR.ERROR_MORE_DATA: lpData = new byte[lpcbData.getValue()]; continue OUTER; case WINERROR.ERROR_SUCCESS: return lpData; } throw new JnaException(r); } }
public RegistryKey open(String subKeyName, int access) { IntByReference pHandle = new IntByReference(); check(Advapi32.INSTANCE.RegOpenKeyEx(handle, subKeyName, 0, access, pHandle)); return new RegistryKey(this,subKeyName,pHandle.getValue()); }
/** * Get all sub keys of a key. * * @return array with all sub key names */ public Collection<String> getSubKeys() { WINBASE.FILETIME lpftLastWriteTime; TreeSet<String> subKeys = new TreeSet<String>(); char[] lpName = new char[256]; IntByReference lpcName = new IntByReference(256); lpftLastWriteTime = new WINBASE.FILETIME(); int dwIndex = 0; while (Advapi32.INSTANCE.RegEnumKeyEx(handle, dwIndex, lpName, lpcName, null, null, null, lpftLastWriteTime) == WINERROR.ERROR_SUCCESS) { subKeys.add(new String(lpName, 0, lpcName.getValue())); lpcName.setValue(256); dwIndex++; } return subKeys; }
result = Advapi32.INSTANCE.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null, lpType, lpData, lpcbData); switch (result) {
/** * Writes a String value. */ public void setValue(String name, String value) { try { byte[] bytes = value.getBytes("UTF-16LE"); int newLength = bytes.length+2; // for 0 padding byte[] with0 = new byte[newLength]; System.arraycopy(bytes, 0, with0, 0, newLength); check(Advapi32.INSTANCE.RegSetValueEx(handle, name, 0, WINNT.REG_SZ, with0, with0.length)); } catch (UnsupportedEncodingException e) { throw new AssertionError(e); } }
/** * Does a specified value exist? */ public boolean valueExists(String name) { IntByReference pType, lpcbData; byte[] lpData = new byte[1]; pType = new IntByReference(); lpcbData = new IntByReference(); OUTER: while(true) { int r = Advapi32.INSTANCE.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData); switch(r) { case WINERROR.ERROR_MORE_DATA: lpData = new byte[lpcbData.getValue()]; continue OUTER; case WINERROR.ERROR_FILE_NOT_FOUND: return false; case WINERROR.ERROR_SUCCESS: return true; default: throw new JnaException(r); } } }
public RegistryKey open(String subKeyName, int access) { IntByReference pHandle = new IntByReference(); check(Advapi32.INSTANCE.RegOpenKeyEx(handle, subKeyName, 0, access, pHandle)); return new RegistryKey(this,subKeyName,pHandle.getValue()); }
/** * Get all sub keys of a key. * * @return array with all sub key names */ public Collection<String> getSubKeys() { WINBASE.FILETIME lpftLastWriteTime; TreeSet<String> subKeys = new TreeSet<String>(); char[] lpName = new char[256]; IntByReference lpcName = new IntByReference(256); lpftLastWriteTime = new WINBASE.FILETIME(); int dwIndex = 0; while (Advapi32.INSTANCE.RegEnumKeyEx(handle, dwIndex, lpName, lpcName, null, null, null, lpftLastWriteTime) == WINERROR.ERROR_SUCCESS) { subKeys.add(new String(lpName, 0, lpcName.getValue())); lpcName.setValue(256); dwIndex++; } return subKeys; }
result = Advapi32.INSTANCE.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null, lpType, lpData, lpcbData); switch (result) { lpData = new byte[lpcbData.getValue()]; lpcchValueName = new IntByReference(16384); check(Advapi32.INSTANCE.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null, lpType, lpData, lpcbData));
/** * Writes a DWORD value. */ public void setValue(String name, int value) { 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); check(Advapi32.INSTANCE.RegSetValueEx(handle, name, 0, WINNT.REG_DWORD, data, data.length)); }
/** * Does a specified value exist? */ public boolean valueExists(String name) { int r = Advapi32.INSTANCE.RegQueryValueEx(handle, name, null, new IntByReference(), new byte[1], new IntByReference()); switch(r) { case WINERROR.ERROR_FILE_NOT_FOUND: return false; case WINERROR.ERROR_SUCCESS: return true; default: throw new JnaException(r); } }
/** * Deletes this key (and disposes the key.) */ public void delete() { check(Advapi32.INSTANCE.RegDeleteKey(handle, path)); dispose(); }
public RegistryKey open(String subKeyName, int access) { IntByReference pHandle = new IntByReference(); check(Advapi32.INSTANCE.RegOpenKeyEx(handle, subKeyName, 0, access, pHandle)); return new RegistryKey(this,subKeyName,pHandle.getValue()); }
public void dispose() { if(handle!=0) Advapi32.INSTANCE.RegCloseKey(handle); handle = 0; }
public void deleteValue(String valueName) { check(Advapi32.INSTANCE.RegDeleteValue(handle, valueName)); }
/** * Get all sub keys of a key. * * @return array with all sub key names */ public Collection<String> getSubKeys() { WINBASE.FILETIME lpftLastWriteTime; TreeSet<String> subKeys = new TreeSet<String>(); char[] lpName = new char[256]; IntByReference lpcName = new IntByReference(256); lpftLastWriteTime = new WINBASE.FILETIME(); int dwIndex = 0; while (Advapi32.INSTANCE.RegEnumKeyEx(handle, dwIndex, lpName, lpcName, null, null, null, lpftLastWriteTime) == WINERROR.ERROR_SUCCESS) { subKeys.add(new String(lpName, 0, lpcName.getValue())); lpcName.setValue(256); dwIndex++; } return subKeys; }