Results 1 to 5 of 5
  1. #1
    durino13 is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default Jni registry 'access denied' error.

    Hi,

    First of all .. I post this question in this forum, because the original component site (JNIRegistry) does not provide a dedicated forum, nor a mailing list.

    Second, I have checked google here and there, but I was not able to find an answer ..

    I have a problem reading the remote registry with my Java application (software scanning application). My application runs fine on Windows XP, but fails to scan computers, while the scanning computer is running Windows 7. I have disabled the UAC on Windows 7, but I still get this error:

    Error:

    INFO [ scanForSoftware() ] - gdmpc386( Adrian Dumitru ): scanning started ..
    INFO [ connect() ] - 'net use' exit value = 0
    INFO [ scanForSoftware() ] - gdmpc386: com.ice.jni.registry.RegistryException: Registry API Error 5, 'access denied' - 'RegOpenKeyEx()'
    com.ice.jni.registry.RegistryException: Registry API Error 5, 'access denied' - 'RegOpenKeyEx()'
    at com.ice.jni.registry.RegistryKey.openSubKey(Native Method)
    at gdm.softauditor.model.ComputerModel.scanForSoftwar e(ComputerModel.java:398)
    at gdm.softauditor.model.ComputerModel.scan(ComputerM odel.java:729)
    at gdm.softauditor.SoftwareAuditorAgent.customCompute rSource(SoftwareAuditorAgent.java:124)
    at gdm.softauditor.SoftwareAuditorAgent.main(Software AuditorAgent.java:105)
    INFO [ scanForSoftware() ] - gdmpc386( Adrian Dumitru ): 0 software entries found.
    INFO [ scanForSoftware() ] - gdmpc386( Adrian Dumitru ): scanning completed ..
    INFO [ main() ] - 1 computers successfully scanned.
    INFO [ main() ] - Application completed ..

    Notice, that the 'net use' command returns 0 return value.

    OS:

    Problem occurs on Windows 7. It works fine on Windows XP.

    This is how I connect to the remote computer in order to scan the registry:

    Java Code:
    private void connect() {
    
            String[] cmd = new String[3];
            cmd[0] = "cmd.exe";
            cmd[1] = "/C";
            cmd[2] = "net use \\\\" + getComputerName() + "\\ipc$ /user:" + getDomain() + "\\" + getUserName() + " " + getPassword();
    
            Runtime rt = Runtime.getRuntime();
    
            try {
    
                Process proc = rt.exec(cmd);
                int exitValue = proc.waitFor();
                logger.info("'net use' exit value = " + exitValue);
                //TODO This line should be tested. If removed, I susspect, it fails to connect to remote registry.
                Thread.sleep(4000);
    
            } catch (Exception ex) {
                logger.severe("Exception occured while tried to connect to computer");
            }
    
        }

    This is how I scan for the software:

    Java Code:
    private List<String> scanForSoftware() {
    
            logger.info(getComputerName() + "( " + getComputerDescription() + " ): scanning started ..");
    
            connect();
    
            List installedSoftware = new ArrayList();
    
            try {
    
                RegistryKey remoteKey = null;
                RegStringValue value = null;
                RegistryKey toplevelKey = Registry.getTopLevelKey("HKEY_LOCAL_MACHINE");
                remoteKey = toplevelKey.connectRegistry("\\\\" + getComputerName() + "\\");
                [COLOR="Red"][B]RegistryKey key = remoteKey.openSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall", RegistryKey.ACCESS_READ);[/B][/COLOR]
    
                Enumeration enumer = key.keyElements();
    
                //build a list of all installed software
                while (enumer.hasMoreElements()) {
    
                    try {
    
                        //monitor progress
                        //setProgress(Math.round(((float) cycle / (float) softwareCount) * 100));
                        //test = Math.round(((float) cycle / (float) softwareCount) * 100);
    
                        String regPath = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + (String) enumer.nextElement();
                        key = remoteKey.openSubKey(regPath, RegistryKey.ACCESS_READ);
                        value = (RegStringValue) key.getValue("DisplayName");
                        installedSoftware.add(value.getData());
    
                    } catch (NoSuchKeyException ex) {
                        //System.out.println("    No such key. Aborting.");
                    } catch (NoSuchValueException ex) {
                        //System.out.println("    Key not found in registry. Ignoring.");
                    } catch (RegistryException ex) {
                        //System.out.println("    Registry exception occured. Ignoring.");
                    } catch (IllegalArgumentException ex) {
                        //AppHelper.logErrorMessage(ex);
                    }
    
                }
    
            } catch (NoSuchKeyException ex) {
                logger.info("Can not get key in the registry for " + this.getComputerName());
                ex.printStackTrace();
            } catch (RegistryException ex) {
                logger.info(this.getComputerName() + ": " + ex.toString());
                ex.printStackTrace();
            }
    
            disconnect();
    
            logger.info(getComputerName() + "( " + getComputerDescription() + " ): " + installedSoftware.size() + " software entries found.");
            logger.info(getComputerName() + "( " + getComputerDescription() + " ): scanning completed ..");
    
            return installedSoftware;
    
        }
    Questions:

    1.
    Do I authenticate correctly to the remote computer with the 'net use'? Or is there other recommended way to authenticate in order to reach remote computer registry?

    2.
    I have disabled the UAC on Windows 7 completely (see attachment). Any idea, what else am I doing wrong?

    I fight with this problem for weeks ;-/

    Many thanks for your help in advance.

    Juraj

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Sounds like a question for windows, seeing as how it semms to simply have to do with accessing a remote registry key. My guess would be that they either disabled that completely, or at least made it much harder. Security, you know, its a beach.

  3. #3
    durino13 is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default ...

    One important thing I forgot to mention.

    I get the 'access denied' error only when scanning computers from different domain. Although, there's a trust relationship set between domains, I explicitly authenticate like this (again, this works with XP):

    net use \\computername\ipc$ password /user:DOMAIN\username

    It is likely possible, that the error is in the authentication ..

    Honestly, I don't like this 'net use' authentication method. I would be more happy to use some native Java methods with decent interface/return values ..

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Again. All I can say is that it seems to be a Windows question.

  5. #5
    narnedrarajak is offline Member
    Join Date
    Sep 2011
    Location
    BHOPAL (M.P.)
    Posts
    1
    Rep Power
    0

    Default Re: Jni registry 'access denied' error.

    Hi dear Thanks for the coding you have posted .Please help I m persuing MCA VI sem from IGNOU and i have to submit project that seems like yours I want to retrive program list installed on other pc what your coding which you have posted is not clear to me bcs im new for java but i have to that project so please help me revert soon.
    I want complet coding and detailed explanation where to put files of registry jni package,

Similar Threads

  1. Replies: 6
    Last Post: 02-10-2011, 10:55 AM
  2. Access is denied
    By tholland in forum New To Java
    Replies: 2
    Last Post: 12-20-2010, 09:57 PM
  3. access denied
    By Dennis in forum Advanced Java
    Replies: 8
    Last Post: 06-05-2010, 09:46 AM
  4. Access registry
    By kkk in forum Advanced Java
    Replies: 8
    Last Post: 09-01-2009, 01:16 PM
  5. [SOLVED] Access Denied error using FileInputStream
    By xcallmejudasx in forum New To Java
    Replies: 8
    Last Post: 05-21-2009, 05:13 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •