使用32位应用程序获取syswow64目录

Nis*_*sim 13 .net 64-bit environment-variables

我正在尝试在系统目录中找到一个文件.问题是在使用时

Environment.SystemDirectory
Run Code Online (Sandbox Code Playgroud)

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

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

有任何想法吗?

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

Chr*_*ich 13

Environment.GetFolderPath(Environment.SpecialFolder.SystemX86)改用.


Nis*_*sim 9

使用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()
}
Run Code Online (Sandbox Code Playgroud)

System32在x86和SysWow64x64上返回