4

exe file using Process.Start() but it throws the "Win32Exception the parameter is incorrect".

Process p = new Process();
Process.Start("C:\Program Files\APS2PP\keyl2000.exe");

I can run this file through command prompt successfully.

Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
Mukesh Gupta
  • 49
  • 1
  • 2
  • 3

4 Answers4

7
Process.Start("C:\Program Files\APS2PP\keyl2000.exe")

Use double backslashes or put a @ in front of the string.

 Process.Start(@"C:\Program Files\APS2PP\keyl2000.exe");
mklement0
  • 382,024
  • 64
  • 607
  • 775
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
2

From: http://msdn.microsoft.com/en-us/library/53ezey2s.aspx

Win32Exception - An error occurred when opening the associated file.

1) If you're going to use the static method of Process.Start(String) you don't really need to declare a Process object.

//Use...
Process p = new Process();
p.StartInfo = new ProcessStartInfo(filename);
p.Start();

//Or...

Process.Start(filename);

2) The exception is basically saying that it can not open that file for some reason. Are you sure the path is correct? Have you tried opening that file manually?

3) Make sure to define your file paths somewhere more organized. Such as a settings file. This also helps eliminate the need for escaping the characters. But, if you insist on leaving that string inline, at least remove the need for escape characters by preceding it with the @ symbol (@"C:\Program Files\SomeFile.exe")

myermian
  • 31,823
  • 24
  • 123
  • 215
0

Any details on the Exception?

According to: http://msdn.microsoft.com/en-us/library/system.componentmodel.win32exception.aspx this exception has an internal exception code so you can google it and see exactly what happened.

Machinarius
  • 3,637
  • 3
  • 30
  • 53
0

I had the same error when I tried putting arguments in the same string as the executable name, i.e. the equivalent of:

Process p = new Process();
Process.Start("C:\Program Files\APS2PP\keyl2000.exe /t keyfile.dat");

I didn't realise they need to be supplied in separate strings.

Tim Cooper
  • 10,023
  • 5
  • 61
  • 77