Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting syswow64 directory using 32-bit application

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

Environment.SystemDirectory

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

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

Any ideas?

EDIT: 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

like image 557
Nissim Avatar asked Aug 22 '10 09:08

Nissim


2 Answers

Use Environment.GetFolderPath(Environment.SpecialFolder.SystemX86) instead.

like image 102
Chris Schmich Avatar answered Nov 08 '22 18:11

Chris Schmich


Using the SHGetSpecialFolderPath function:

[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()
}

Will return System32 on x86, and SysWow64 on x64

like image 32
Nissim Avatar answered Nov 08 '22 18:11

Nissim