如何从 32 位代码以 64 位方式启动 Windows 进程? [英] How to launch a Windows process as 64-bit from 32-bit code?

查看:54
本文介绍了如何从 32 位代码以 64 位方式启动 Windows 进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要在写入 HKLM 注册表配置单元时在 Vista 中弹出 UAC 对话框,我们选择不使用 Win32 注册表 API,因为当缺少 Vista 权限时,我们需要以管理员权限重新启动整个应用程序.相反,我们这样做:

To pop up the UAC dialog in Vista when writing to the HKLM registry hive, we opt to not use the Win32 Registry API, as when Vista permissions are lacking, we'd need to relaunch our entire application with administrator rights. Instead, we do this trick:

ShellExecute(hWnd, "runas" /* display UAC prompt on Vista */, windir + "\Reg", "add HKLM\Software\Company\KeyName /v valueName /t REG_MULTI_TZ /d ValueData", NULL, SW_HIDE);

这个解决方案工作正常,除了我们的应用程序是一个 32 位的,它运行 REG.EXE 命令,因为它是一个使用 WOW 兼容层的 32 位应用程序!:( 如果 REG.EXE 从命令行运行,则它在 64 位模式下正确运行.这很重要,因为如果它作为 32 位应用程序运行,由于 注册表反射.

This solution works fine, besides that our application is a 32-bit one, and it runs the REG.EXE command as it would be a 32-bit app using the WOW compatibility layer! :( If REG.EXE is ran from the command line, it's properly ran in 64-bit mode. This matters, because if it's ran as a 32-bit app, the registry keys will end up in the wrong place due to registry reflection.

那么有什么方法可以从 32 位应用程序以编程方式启动 64 位应用程序,而不是像其父 32 位进程那样使用 WOW64 子系统运行它(即任务管理器中的*"后缀)?

So is there any way to launch a 64-bit app programmatically from a 32-bit app and not have it run using the WOW64 subsystem like its parent 32-bit process (i.e. a "*" suffix in the Task Manager)?

推荐答案

试试这个(来自 32 位进程):

try this (from a 32bit process):

> %WINDIR%sysnative
eg.exe query ...

(发现 此处).

这篇关于如何从 32 位代码以 64 位方式启动 Windows 进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆