3

How I can launch exe file with c# code? So I have this :

Process.Start( @"C:\Program Files (x86)\Photoshop\Photoshop.exe");

But the path can be different in other machines. So is there any ideas to run .exe with different way?

Thanks!

Doniyor Niazov
  • 1,270
  • 1
  • 10
  • 19

3 Answers3

5

I found a solution.

Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application"));
Doniyor Niazov
  • 1,270
  • 1
  • 10
  • 19
1

No, you cannot run an exe file without knowing its location.

The "exception" is if the executable directory is in the PATH environment variable, which is why:

Process.Start("notepad.exe");

works.

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
  • While this is technically true, there are other ways of getting the path besides hardcoding it. – Abion47 Nov 30 '16 at 00:20
  • @Abion47 Sure, there are the special folder classes etc, but that doesn't get past the basic problem of launching an exe regardless of where it is located. – BradleyDotNET Nov 30 '16 at 00:21
0

If i understood you correctly , the executable is in your reach, so just put it in the project directory and do not specify any path (the default is a relative path):

Process.Start("Photoshop.exe");
Dr.Haimovitz
  • 1,568
  • 12
  • 16