简体   繁体   English

从32位Java运行64位Windows命令

[英]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). 我正在使用Java SWT应用程序,该应用程序需要显示安装在本地Windows计算机(64位)中的ODBC驱动程序。 I came up with a reg query statement which will do that. 我想出了一个reg查询语句,它将做到这一点。

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. 但是,当我从32位Java运行相同的命令时,reg查询失败。 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. 一经阅读,我发现Windows具有注册表重定向功能,这阻止了我的32位Java使用64位注册表和64位reg.exe。

I tried to hardcode the path for 64 bit reg.exe in the system32 folder but it is still failing. 我试图在system32文件夹中对64位reg.exe的路径进行硬编码,但仍然失败。

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. 我必须使用sysnative文件夹才能从32位应用程序访问64位工具。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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