简体   繁体   中英

Run 64 bit windows command from 32 bit java

I'm working on a java SWT application which needs to show the ODBC drivers installed in the local windows machine(64 bit). I came up with a reg query statement which will do that.

reg query "HKLM\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources" /f *

when I run this command in command prompt I'm getting the expected output. But when I run the same command from 32 bit java, the reg query fails. Here is the sample code.

String cmd = "reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources\" /f *";
        System.out.println(cmd);
        Process p = Runtime.getRuntime().exec(cmd);
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = in.readLine()) != null) {
            System.out.println(line);
        }

        line = null;
        BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        while ((line = err.readLine()) != null) {
            System.out.println(line);
        }

Output

ERROR: The system was unable to find the specified registry key or value.

Upon some reading I found that windows has Registry Redirection which is preventing my 32 bit java to use 64 bit registry and 64 bit reg.exe.

I tried to hardcode the path for 64 bit reg.exe in the system32 folder but it is still failing.

String cmd = "C:\\Windows\\System32\\reg.exe query \"HKLM\\SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources\" /f *";

Anyway to resolve this issue.

Thanks in advance.

thanks for the help guys. i found the solution. I have to use sysnative folder to access 64 bit tools from a 32 bit application.

so i updated my req query statement to this

String cmd = "C:\\Windows\\Sysnative\\reg.exe query \"HKLM\\SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources\" /f *";

output

HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources
jbb    REG_SZ    IBM Integration (9.0.0.1) - DataDirect Technologies 7.0 64-BIT Oracle Wire Protocol

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM