bcdedit cannot be found by rust executable

0

I am trying to call bcdedit from within a rust executable using std::process::Command.

When executing the resulting program on Windows 10 in an administrator command prompt I get:

'bcdedit' is not recognized as an internal or external command, operable program or batch file..

  • Calling bcdedit directly in the same shell works just fine.
  • Calling it with its absolute path makes no difference.
  • Calling other executables works ok.
  • Calling bcdedit directly without using cmd.exe returns error: Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }.

This happens on Windows 10 Pro, version 1903, Build 18362.657. I have another Windows 10 installed (Windows 10 Pro, version 1809, build 17763.1039) on which this works ok.

I have a rust snippet that exposes the problem:

use std::process::{Command, Stdio};
use std::env::args;
fn main() {
    let mut cmd_args = args();
    let cmd = if let Some(arg1) = cmd_args.nth(1) {
        arg1
    } else {
        String::from("dir")
    };

    println!("command is '{}'", cmd);
    match Command::new("cmd.exe")
        .arg("/c")
        .arg(&cmd)
        .stdout(Stdio::piped())
        .stderr(Stdio::piped())
        .output() {
        Ok(output) => {
            println!("Executed '{}', success: {}", cmd, output.status.success());
            println!("stdout: '{}'", String::from_utf8_lossy(&output.stdout));
            println!("stderr: '{}'", String::from_utf8_lossy(&output.stderr));
        }
        Err(why) => {
            eprintln!("Failed to execute '{}', error: {:?}", &cmd, why);
        }
    }
}

Thomas

Posted 2020-02-19T19:00:27.003

Reputation: 1

Msgbox box out the command you are executing. – Mark – 2020-02-19T20:57:12.457

Maybe run Process Monitor, see what's going on? Is it a 32 or 64-bit exe? Does it work %windir%\sysnative\bcdedit.exe for example? – HelpingHand – 2020-02-19T21:12:37.570

Answers

0

@HelpingHand's comment pointed in the right direction. Problem was that I accidentally created a 32bit executable while assuming I was creating 64 bit. Apparently bcdedit on 64bit windows is only available as 64bit and as such is not accessible for 32bit executables in the normal location (C:\Windows\system32\bcdedit.exe). It can be accessed though at C:\Windows\sysnative\bcdedit.exe.

Thomas

Posted 2020-02-19T19:00:27.003

Reputation: 1

Questions asked in an answer cannot be answered by the community. If you want an answer to your question, it has to be submitted as a question, so an answer can be submitted – Ramhound – 2020-02-21T01:57:28.100