3

I want to change the BCD from my .NET application. To do so, I've created this little snippet:

static void RunBcdEdit() 
{
    Process process = new Process();
    process.StartInfo.FileName = "c:\\Windows\\System32\\bcdedit.exe";
    process.StartInfo.UseShellExecute = false;        
    process.WaitForExit();
}

The strange thing is that it throws an exception saying that

the system cannot find the file especified

What's wrong with this?

Aleks Andreev
  • 7,016
  • 8
  • 29
  • 37
SuperJMN
  • 13,110
  • 16
  • 86
  • 185
  • Whelp, sounds like c:\Windows\System32\bcdedit.exe is sometimes inaccesible? – Davesoft Jun 29 '18 at 17:59
  • 2
    System32 is a very 'odd' directory. If you have a 32-bit app trying to access it, it is redirected to \windows\syswow64. This may be what is tripping you up. – simon at rcl Jun 29 '18 at 18:04
  • Project > Properties > Build tab, untick the "Prefer 32-bit" checkbox. You don't prefer it. Learn more about the File System Redirector that is used on a 64-bit OS to keep 32-bit apps compatible from [this page](https://learn.microsoft.com/en-us/windows/desktop/winprog64/file-system-redirector). – Hans Passant Jun 29 '18 at 18:30
  • So, what's the best approach to interact with BCDEdit? Or to modify the BCD? – SuperJMN Jun 29 '18 at 18:56

1 Answers1

1

I've experienced similar issues with running applications out of System32. A workaround I found was using SysNative. In testing there was no consistency when System32 would work or when SysNative would work for different applications that reside in System32.

static void RunBcdEdit() 
{
    Process process = new Process();
    process.StartInfo.FileName = "c:\\Windows\\SysNative\\bcdedit.exe";
    process.StartInfo.UseShellExecute = false;        
    process.WaitForExit();
}
Matt Nelson
  • 991
  • 1
  • 9
  • 21