Java wrapper for Windows registry API RegCloseKey() - Java Native OS

Java examples for Native OS:Windows

Description

Java wrapper for Windows registry API RegCloseKey()

Demo Code


//package com.java2s;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.prefs.Preferences;

public class Main {
    /**/*from w  ww  .  j  a  v a2 s  .  c o m*/
     * Error because acces to the specified key was denied
     */
    public static final int ERROR_ACCESS_DENIED = 5;
    private static final Preferences systemRoot = Preferences.systemRoot();
    private static Method windowsRegCloseKey = null;

    /**
     * Java wrapper for Windows registry API RegCloseKey()
     * 
     * @param hKey
     *            The Native Handle
     * @return The Error Code
     */
    public static int RegCloseKey(int hKey) {
        try {
            return ((Integer) windowsRegCloseKey.invoke(systemRoot,
                    new Object[] { new Integer(hKey) })).intValue();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return ERROR_ACCESS_DENIED;
    }
}

Related Tutorials