-1

I'm trying to make a program, which can open other programs, but I need help, because if I run a program, with

Process.Start(ExePath)

I get errors like 'cannot find 'File.*' file'. but normally the program works when I start it manually it just works normally does someone knows how to fix this?

Thanks in advance

  • What is the value of `ExePath`? – Mathias R. Jessen Mar 23 '16 at 19:21
  • What's the value of ExePath? And does that precise executable exist in your system? – ManoDestra Mar 23 '16 at 19:21
  • 3
    You need to set the correct working directory. See http://stackoverflow.com/questions/114928/net-process-start-default-directory . – Paul-Jan Mar 23 '16 at 19:22
  • For example: Directory.GetCurrentDirectory()+"\\Games\\Game.exe" – Daniël Verhoef Mar 23 '16 at 19:23
  • That will make it dependent on where your program is run from, which isn't necessarily the same directory as the assembly. You should use the absolute path of your executing assembly as the root in this instance, if the Game.exe always exists in the Games subfolder of the executing assembly. – ManoDestra Mar 23 '16 at 19:24
  • make a breakpoint at `Process.Start(...)` and check the value of `ExePath`). Then open the explorer and check if the exact path exists. – derpirscher Mar 23 '16 at 19:34

1 Answers1

0

You can build a full qualified path starting from your current application directory like this:

string exepath = Path.Combine(Environment.CurrentDirectory, "Games", "Game.exe");
Process.Start(exepath);

adopted from Specifying a relative path

Community
  • 1
  • 1
Filburt
  • 17,626
  • 12
  • 64
  • 115