You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Emmanuel Bourg (Commented) (JIRA)" <ji...@apache.org> on 2011/10/24 22:30:32 UTC

[jira] [Commented] (CONFIGURATION-312) WindowsConfiguration

    [ https://issues.apache.org/jira/browse/CONFIGURATION-312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13134453#comment-13134453 ] 

Emmanuel Bourg commented on CONFIGURATION-312:
----------------------------------------------

There is also a JNI-less solution to read the registry by parsing the output of the {{reg query}} command line tool.

http://technet.microsoft.com/en-us/library/cc742028%28WS.10%29.aspx

                
> WindowsConfiguration
> --------------------
>
>                 Key: CONFIGURATION-312
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-312
>             Project: Commons Configuration
>          Issue Type: New Feature
>          Components: Format
>            Reporter: Emmanuel Bourg
>             Fix For: 2.x
>
>
> This is a RFE to implement a configuration backed by the windows registry.
> It can be implemented using an external library such as the ICE JNI Registry :
> http://www.trustice.com/java/jnireg
> It could also be implemented by hacking around the private WindowsPreferences class from the JDK (with no guarantee it will work on later versions, on other VMs, or on environments with a SecurityManager). Here is an example using this approach and displaying the user's data directory :
> {code:java}
> Preferences winPrefs = Preferences.userRoot();
> Class cls = winPrefs.getClass();
> Method openKey = cls.getDeclaredMethod("openKey", byte[].class, int.class, int.class);
> openKey.setAccessible(true);
> Method closeKey = cls.getDeclaredMethod("closeKey", int.class);
> closeKey.setAccessible(true);
> Method winRegQueryValue = cls.getDeclaredMethod("WindowsRegQueryValueEx", int.class, byte[].class);
> winRegQueryValue.setAccessible(true);
> Method winRegEnumValue = cls.getDeclaredMethod("WindowsRegEnumValue1", int.class, int.class, int.class);
> winRegEnumValue.setAccessible(true);
> Method winRegQueryInfo = cls.getDeclaredMethod("WindowsRegQueryInfoKey1", int.class);
> winRegQueryInfo.setAccessible(true);
> Integer keyHandle = (Integer) openKey.invoke(winPrefs, toByteArray("Volatile Environment"), KEY_READ, KEY_READ);
> byte[] array = (byte[]) winRegQueryValue.invoke(winPrefs, keyHandle, toByteArray("APPDATA"));
> closeKey.invoke(winPrefs, keyHandle);
> System.out.println(new String(array));
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira