Marlon Davies
Marlon Davies

Reputation: 25

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();

Upvotes: 0

Views: 164

Answers (2)

Marlon Davies
Marlon Davies

Reputation: 25

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();

Upvotes: 0

shingo
shingo

Reputation: 27021

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.

  1. Use Sysnative directory

    p.StartInfo.FileName = @"C:\Windows\Sysnative\cmd";
    
  2. 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))
    
  3. Copy cmd.exe from C:\Windows\System32 to your working directory.

Upvotes: 1

Related Questions