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 (JIRA)" <ji...@apache.org> on 2008/02/21 23:56:19 UTC

[jira] Created: (CONFIGURATION-312) WindowsConfiguration

WindowsConfiguration
--------------------

                 Key: CONFIGURATION-312
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-312
             Project: Commons Configuration
          Issue Type: New Feature
            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.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CONFIGURATION-312) WindowsConfiguration

Posted by "Emmanuel Bourg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CONFIGURATION-312?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bourg updated CONFIGURATION-312:
-----------------------------------------

    Component/s: Format

> 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.
-
You can reply to this email to add a comment to the issue online.