Steven
Steven

Reputation: 2558

Running 64-bit executable in System32 from 32-bit code

I am trying to run an executable from a 32-bit C# app (on a 64-bit OS), but I’m getting “The system cannot find the file specified” probably because wsqmcons.exe does not exist in C:\Windows\SySWOW64. The file does exist in System32. What is the best way to run wsqmcons.exe from code, if possible?

Process p = new Process();
p.StartInfo.Arguments = "-f";
p.StartInfo.FileName = @"C:\Windows\System32\wsqmcons.exe";
p.Start();
p.WaitForExit();
Verify.AreEqual(0, p.ExitCode);

Upvotes: 1

Views: 1377

Answers (2)

Reza M.
Reza M.

Reputation: 1223

A 64-bit executable file located under %windir%\System32 cannot be launched from a 32-bit process, because the file system redirector redirects the path to %windir%\SysWOW64. Do not disable redirection to accomplish this; use %windir%\Sysnative instead. For more information, see File System Redirector.

Quote from http://msdn.microsoft.com/en-us/library/windows/desktop/aa384203%28v=vs.85%29.aspx

Upvotes: 1

user957902
user957902

Reputation: 3060

You will need to turn off the file system redirection on your 32 bit process with the Wow64DisableWow64FsRedirection and the re-enable it with Wow64RevertWow64FsRedirection.

Upvotes: 1

Related Questions