运行 64 位 windows 来自 32 位的命令 java

Run 64 bit windows command from 32 bit java

我正在开发 java SWT 应用程序,它需要显示安装在本地 windows 机器(64 位)中的 ODBC 驱动程序。我提出了一个 reg 查询语句来执行此操作。

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

当我在命令提示符下 运行 此命令时,我得到了预期的输出。但是当我 运行 来自 32 位 java 的相同命令时,reg 查询失败。这是示例代码。

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);
        }

输出

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

经过一些阅读,我发现 windows 具有注册表重定向功能,这会阻止我的 32 位 java 使用 64 位注册表和 64 位 reg.exe。

我尝试在 system32 文件夹中硬编码 64 位 reg.exe 的路径,但它仍然失败。

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

无论如何都要解决这个问题。

提前致谢。

感谢大家的帮助。我找到了解决方案。我必须使用 sysnative 文件夹从 32 位应用程序访问 64 位工具。

所以我将我的请求查询语句更新为这个

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

输出

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