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

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

问题描述

我试图找到系统目录中的文件。 的问题是,当使用

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

Environment.SystemDirectory

在一个64位的机器,我仍然得到,而不是Systemwow64目录下的System32目录。

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

我需要在x86机器上的system32目录下,并在x64SystemWow64目录

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

任何想法?

编辑: 为了找到我使用了GetSystemWow64Directory的SysWow64文件。 (点击此处了解详情: 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()
}

将返回 System32下在x86和 SysWow64文件在x64

Will return System32 on x86, and SysWow64 on x64

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

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