gpt4 book ai didi

c# - 如何在 win64 上禁用重定向

转载 作者:太空狗 更新时间:2023-10-30 00:25:22 25 4
gpt4 key购买 nike

我想将 c:\Windows\regedit.exe 复制到名称为 regedit2.exe 的同一目录但是当我尝试复制它时,出现错误说找不到 regedit.exe 文件”或者有时将它复制到 windows\SysWOW64 目录下。实际上我知道 win64 正在重定向它但是如何我可以禁用重定向并将 windows/regedit.exe 复制到 windows/regedit2.exe 吗?我的示例代码是

if(File.Exists(@"c:\Windows\regedit.exe"))
try
{
File.Copy(@"c:\Windows\regedit.exe", @"c:\Windows\regedit2.exe", true);
}
catch (Exception ex){}

有没有人可以帮助我

最佳答案

有可用的 Win32 函数可以禁用和启用重定向。

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);

例子:

IntPtr wow64Value = IntPtr.Zero;

// Disable redirection.
Wow64DisableWow64FsRedirection(ref wow64Value);

// Do whatever you need
// .....................

// Re-enable redirection.
Wow64RevertWow64FsRedirection(wow64Value);

关于c# - 如何在 win64 上禁用重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17487653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com