To start working with Windows registry from your Java application WinRegistry.dll file should be discoverable by JVM. You can do it euther by adding path to this file to your PATH
set PATH="Directory with WinRegistry.dll";%PATH%or by copying WinRegistry.dll to your Windows directory or by running java with parameter "java.library.path"
java -cp dist/jndi2r.jar;... -Djava.library.path="Directory with WinRegistry.dll" ...jndi2r.jar should be added to the classpath. Our service provider is tested to work with JDK1.3 and JDK1.4 and on Windows XP/2000/NT/Me/9x
To enable registry operations in your application you should create InitialContext.
This can be done as follows:
Hashtable environment = new Hashtable();
environment.put("java.naming.factory.initial", "com.scand.jndi.registry.RegistryInitialContextFactory");
Context c = new InitialContext(environment);
c.lookup(c.getEnvironment().get("com.scand.jndi.registry.entryPrefix"));
If not set the RegistryContext will add the default value to its environment automatically.
The default is "". Names in JNDI should be unique but in Windows registry you can have key and value
in this key with the same name, to access such keys and values you should set non-empty entryPrefix and
prefix all value names with entryPrefix. When entryPrefix id default ("") then you have some restrictions
(cannot access key's default value and keys/values with equal names).
Names in Registry are not case sensitive ("key" and "KEY" is the same).
For more convenient use the following name aliases are defined:
"HKEY_CLASSES_ROOT" is aliased to "HKCR"
"HKEY_CURRENT_CONFIG" is aliased to "HKCC"
"HKEY_CURRENT_USER" is aliased to "HKCU"
"HKEY_LOCAL_MACHINE" is aliased to "HKLM"
"HKEY_USERS" is aliased to "HKU"
Service provider has support of common registry types: REG_SZ (mapped to java.lang.String), REG_DWORD (mapped to java.lang.Long) and REG_BINARY (mapped to com.scand.jndi.registry.ByteArray). You can also store any serialized java object as REG_BINARY. Support of other types will be in the next release.
In demo version you can create keys/values and read them but you cannot delete them or modify value's content (OperationNotSupported exception will be thrown).
For more information see com.scand.jndi.registry.demo.simple.Simple.java, com.scand.jndi.registry.demo.RegEdit.java and API documentation. You can run demo RegEdit program as
java -jar RegEdit.jarAlso you can use JNDI Browser that can be downloaded from http://java.sun.com/products/jndi. It should be run as follows
java -cp "jndibrowser.jar;jndi2r.jar" examples.browser.Browser "Registry|com.scand.jndi.registry.RegistryInitialContextFactory"Before running example programs make sure WinRegistry.dll is in your PATH.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SCAND BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.