'c# Process() does not run certain files when compiled in 32bit
This code works in a 64 Bit build but not in a 32 bit build. Is it possible to make it work in a 32 bit build? What am I doing wrong here?
var p = new Process();
p.StartInfo.FileName = @"C:\Windows\System32\msconfig.exe";
p.Start();
Solution 1:[1]
There is a trick, you can use 64-bit cmd.exe to pull a 64-bit application up.
var p = new Process();
p.StartInfo.FileName = "cmd";
p.StartInfo.Arguments = @"/c start """" C:\Windows\System32\msconfig.exe";
p.Start();
The problem is a 32-bit application cannot directly access 64-bit cmd.exe, so there are 3 workarounds to achieve the purpose.
Use Sysnative directory
p.StartInfo.FileName = @"C:\Windows\Sysnative\cmd";
Turn off redirection with the windows API
[DllImport("kernel32.dll")] private static extern bool Wow64DisableWow64FsRedirection(ref IntPtr oldValue); IntPtr intptr = IntPtr.Zero; if(Wow64DisableWow64FsRedirection(ref intptr))
Copy cmd.exe from C:\Windows\System32 to your working directory.
Solution 2:[2]
I was able to use the path below to run the msconfig from a 32 bit process:
C:\Windows\**sysnative**\cmd.exe|/Q /S /C msconfig.exe
var p = new Process();
p.StartInfo.FileName = @"C:\Windows\sysnative\msconfig.exe";
p.Start();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Jeremy Caney |