使用 32 位应用程序获取 syswow64 目录 [英] Getting syswow64 directory using 32-bit application

查看:26
本文介绍了使用 32 位应用程序获取 syswow64 目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在系统目录中查找文件.问题是当使用

I'm trying to find a file inside the system directory. The problem is that when using

Environment.SystemDirectory

在 x64 机器上,我仍然得到 System32 目录,而不是 Systemwow64 目录.

On a x64 machine, i'm still getting the System32 directory, instead of the Systemwow64 directory.

我需要在 x86 机器上获取System32"目录,在 x64 机器上获取SystemWow64"目录

I need to get the "System32" directory on x86 machines, and "SystemWow64" directory on x64

有什么想法吗?

要查找 SysWow64,我正在使用GetSystemWow64Directory".(这里有更多信息:pinvoke请注意,在非 x64 机器上 - 结果为0".希望这对某人有帮助

To find the SysWow64 i'm using the "GetSystemWow64Directory". (more information here: pinvoke Notice that on non-x64 machines - result is '0'. Hope this helps someone

推荐答案

使用 SHGetSpecialFolderPath 函数:

[DllImport("shell32.dll")]
public static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out]StringBuilder lpszPath, int nFolder, bool fCreate);

string GetSystemDirectory()
{
    StringBuilder path = new StringBuilder(260);
    SHGetSpecialFolderPath(IntPtr.Zero,path,0x0029,false);
    return path.ToString()
}

将在 x86 上返回 System32,在 x64 上返回 SysWow64

Will return System32 on x86, and SysWow64 on x64

这篇关于使用 32 位应用程序获取 syswow64 目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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