从32位应用程序打开64位regedit
Open 64 bit regedit from 32 bit application
我正试图使用ShellExecute从我的32位应用程序中打开64位Regedit。
我在Process Explorer中注意到,如果我正常打开Regedit,它会显示图像为64位,但如果我使用ShellExecute从32位应用程序打开C:WindowsRegedit.exe
,Process Explorer会显示图像是32位。
(它确实在Windows目录中打开regedit,而不是在SysWOW64中)
我发现,如果在调用ShellExecute之前使用Wow64DisableWow64FsRedirection
函数,它会打开它的64位映像。但我的应用程序不会在32位XP上运行。
让我困惑的是,无论我以何种方式打开regedit,它们都位于C:Windows
中,并且都是相同的可执行文件。同一个可执行文件怎么可能有两种不同的映像类型?如果没有Wow64DisableWow64FsRedirection
,我如何打开64位的?
您需要检测您是否在使用Is64BitProcess的64位进程中,如果是,则访问指向"Real"System32文件夹的%windir%Sysnative
,以便32位应用程序需要访问64位System32文件夹。
string system32Directory = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "system32");
if(Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess)
{
// For 32-bit processes on 64-bit systems, %windir%system32 folder
// can only be accessed by specifying %windir%sysnative folder.
system32Directory = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "sysnative");
}
这是我用来从32位应用程序启动64位regedit的代码:
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
internal int ExecuteCommand64(string Command, string Parameters)
{
IntPtr ptr = new IntPtr();
bool isWow64FsRedirectionDisabled = Wow64DisableWow64FsRedirection(ref ptr);
if (isWow64FsRedirectionDisabled)
{
//Set up a ProcessStartInfo using your path to the executable (Command) and the command line arguments (Parameters).
ProcessStartInfo ProcessInfo = new ProcessStartInfo(Command, Parameters);
ProcessInfo.CreateNoWindow = true;
ProcessInfo.UseShellExecute = false;
ProcessInfo.RedirectStandardOutput = true;
//Invoke the process.
Process Process = Process.Start(ProcessInfo);
Process.WaitForExit();
//Finish.
// this.Context.LogMessage(Process.StandardOutput.ReadToEnd());
int ExitCode = Process.ExitCode;
Process.Close();
bool isWow64FsRedirectionOK = Wow64RevertWow64FsRedirection(ptr);
if (!isWow64FsRedirectionOK)
{
throw new Exception("Le retour en 32 bits a échoué.");
}
return ExitCode;
}
else
{
throw new Exception("Impossible de passer en 64 bits");
}
}
我用下面的行来称呼它:
ExecuteCommand64(@"c:windowsregedit", string.Format(""{0}"", regFileName));
其中regFilename是我要添加到注册表中的注册表文件。
相关文章:
- 将应用程序从32位移植到64位时出现问题
- 64位机器上的C++内存对齐
- qmake:检测目标位宽(32 位或 64 位)
- 如何在 64 位 vb.net Windows 应用程序中引用 32 位 dll
- Qt 5.11.2 (Clang 8.0 (Apple), 64 位), 找不到 QJSEngine 文件
- 在 64 位边界上对齐C++结构数组?
- 如何为字符串生成唯一但一致的 N 位哈希(小于 64 位)?
- 在 64 位的 c++ 中运行 mstest 测试
- 在两个线程上读/写 64 位,无互斥/锁定/原子
- 浮点数为 32 位和 64 位二进制表示形式
- 是否有 64 位等效于 GetLastInputInfo / LASTINPUTINFO?
- 所有可能的链接生成器与64位密钥
- WinAPI C++如何从 64 位应用程序加载资源
- 在 c++ 中输出 64 位整数
- 使用192/256位整数求和无符号64位整数向量的点积的最快方法
- 如何在 64 位平台上计算 32 位哈希C++?
- 使用 SysNative 在 Visual Studio 中创建 64 位应用程序
- 在 64 位整数内旋转(90°)位矩阵(最多 8x8 位)
- 64 位进程中的 AnyCPU C# DLL 无法引用 64 位C++ DLL(给出错误:无法加载文件或程序集)
- 从32位应用程序打开64位regedit