1

I have the following code which works under Linux :

ProcessStartInfo startInfo = new ProcessStartInfo(); 

// Set in the process the executable and arguments
startInfo.FileName = "ps";
startInfo.Arguments = "a";

Process proc = Process.Start(startInfo);

proc.WaitForExit();

return proc.ExitCode;

However when I try using the process under Windows for a simple commands :

ProcessStartInfo startInfo = new ProcessStartInfo(); 

// Set in the process the executable and arguments
startInfo.FileName = "call";
startInfo.Arguments = "gpedit.msc";

Process proc = Process.Start(startInfo);

proc.WaitForExit();

return proc.ExitCode;

It doesn't work (I know running thins command in cmd.exe works fine).

I get : Win32Exception was unhandled.

I also read this tutorial over again : How do I start a process from C#?

I used process a lot under Linux but I cannot see what I do wrong in Windows.

Community
  • 1
  • 1
Cher
  • 2,789
  • 10
  • 37
  • 64
  • 2
    Is 'call' in the same directory as the executable of your code? – Bsa0 Jul 15 '15 at 14:07
  • 2
    `CALL` is a batch command, only available from the command line. You should be able to just specify `gpedit.msc` as the “file name” without specifying any argument to launch the management tool. – poke Jul 15 '15 at 14:09
  • 1
    gpedit.msc is the process you are trying to run - so that should be the FileName – PaulF Jul 15 '15 at 14:11
  • Did you read the exception yet? – usr Jul 15 '15 at 14:11
  • 1-)Call is indeed in the same directory 2-) I'm gonna try not having the call and report if it works – Cher Jul 15 '15 at 14:26

2 Answers2

2

CALL is a batch command, only available from the command line (poke)

I instead use start and it works fine.

poke
  • 369,085
  • 72
  • 557
  • 602
Cher
  • 2,789
  • 10
  • 37
  • 64
1

Two Options:

Call the MMC executable with GPEDIT parameter

startInfo.FileName = "MMC.EXE";
startInfo.Arguments = "GPEDIT.MSC";

Or call GPEDIT.MSC with no parameters

startInfo.FileName = "GPEDIT.MSC";
poke
  • 369,085
  • 72
  • 557
  • 602
Mike
  • 189
  • 1
  • 5