/** * 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)); }
/** * 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)); }
/** * Returns true if the .NET framework of the given version (or greater) is installed. */ public static boolean isInstalled(int major, int minor) { try { // see http://support.microsoft.com/?scid=kb;en-us;315291 for the basic algorithm // observation in my registry shows that the actual key name can be things like "v2.0 SP1" // or "v2.0.50727", so the regexp is written to accommodate this. RegistryKey key = RegistryKey.LOCAL_MACHINE.openReadonly("SOFTWARE\\Microsoft\\.NETFramework"); try { for( String keyName : key.getSubKeys() ) { if (matches(keyName, major, minor)) return true; } return false; } finally { key.dispose(); } } catch (JnaException e) { if(e.getErrorCode()==2) // thrown when openReadonly fails because the key doesn't exist. return false; throw e; } }
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()); }
/** * Read an int value. */ public int getIntValue(String valueName) { return convertBufferToInt(getValue(valueName)); }
public String getStringValue(String valueName) { return convertBufferToString(getValue(valueName)); }
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 boolean isRoot() { return LIBC.geteuid()==0; }
public RegistryKey open(String subKeyName) { return open(subKeyName,0xF003F/*KEY_ALL_ACCESS*/); }
public void dispose() { if(handle!=0) Advapi32.INSTANCE.RegCloseKey(handle); handle = 0; }
private RegistryKey(RegistryKey ancestor, String path,int handle) { this.handle = handle; this.root = ancestor.root; this.path = combine(ancestor.path,path); }
private void check(int r) { if (r != WINERROR.ERROR_SUCCESS) throw new JnaException(r); }
@Override protected void finalize() throws Throwable { super.finalize(); dispose(); }
public WinIOException(String message, Throwable cause) { super(message); initCause(cause); }
public static boolean isGlibcSupported() { try { GNUCLibrary.LIBC.getpid(); return true; } catch(Throwable t) { return false; } }
public DUMMYUNIONNAME_union(Pointer hIcon_or_hMonitor) { super(); this.hMonitor = this.hIcon = hIcon_or_hMonitor; setType(Pointer.class); }
/** * 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); } }
public RegistryKey openReadonly(String subKeyName) { return open(subKeyName,0x20019/*KEY_READ*/); }
public WinIOException(Throwable cause) { initCause(cause); }