Problem with executing cmd commands in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michaeldebruin
    New Member
    • Feb 2011
    • 134

    #1

    Problem with executing cmd commands in C#

    Hello all,

    I've got the code as shown below:
    Code:
    Process process = new Process();
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                startInfo.FileName = "cmd.exe";
                startInfo.Arguments = "shutdown /r";
                process.StartInfo = startInfo;
                Process.Start(startInfo);
    But somehow, it will start up cmd.exe but it won't execute the command shown at the startInfo.Argum ents.
    Anyone who can help me out?

    Thanks in advance,

    Michael
  • Jwalker
    New Member
    • Jan 2013
    • 3

    #2
    try this
    Code:
                
    Process process = new Process();
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    startInfo.FileName = "cmd.exe";
    startInfo.Arguments = "/C shutdown /r";
    process.StartInfo = startInfo;
    Process.Start(startInfo);
    pass "/C".

    bye.

    Comment

    • michaeldebruin
      New Member
      • Feb 2011
      • 134

      #3
      Thanks it solved the problem, I have no idea why but it's solved now. So Thanks a lot

      Comment

      Working...