0

how can run this cmd command "bcdedit /set testsigning on" by c#? this my code - no run :

        string strCmdLine;
        strCmdLine = "bcdedit /set testsigning on";
        Process.Start("CMD.exe", strCmdLine);
Cédric Guillemette
  • 2,394
  • 1
  • 14
  • 22
sari k
  • 2,051
  • 6
  • 28
  • 34
  • 1
    possible duplicate of [How to start a process from C# (WinForms)](http://stackoverflow.com/questions/181719/how-to-start-a-process-from-c-winforms) – Heinzi Nov 16 '10 at 12:05
  • I do not use bat file, I want to use with cmd.exe – sari k Nov 16 '10 at 12:08
  • What did that thread have to do with bat-files? Anyway, all you need to know is written in the thread mentioned above. Just set `FileName` to the path to cmd, and arguments to `-C ` (if my memory serves me right). – Alxandr Nov 16 '10 at 12:14
  • can you give me an example of code? – sari k Nov 16 '10 at 13:20

3 Answers3

1

You can try System.Diagnostics.Process.Start("CMD.exe", "bcdedit /set testsigning on" );

Sanja Melnichuk
  • 3,465
  • 3
  • 25
  • 46
1

Missing some details on the actual issue here...

Here's my guess, I think you are missing the /c flag.

 string strCmdLine;
 strCmdLine = "/c bcdedit /set testsigning on";
 Process.Start("CMD.exe", strCmdLine);

See the help of cmd.exe for more details on the /c flag (cmd /?).

Cédric Guillemette
  • 2,394
  • 1
  • 14
  • 22
0

You can do it like this, just replace "format" with "bcdedit", and "/? with "/set testsigning on"

ProcessStartInfo info = new ProcessStartInfo("format", "/?");
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
string output = Process.Start(info).StandardOutput.ReadToEnd();
Console.WriteLine(output);

You don't need the last 2 lines if you do not care about the output, you should also consider redirecting error output and forwarding it to the console as well (in case you get any error

Jason
  • 3,844
  • 1
  • 21
  • 40