Process.Start(variable) to open an application without knowing the installation location

Asked

Viewed 1,215 times

1

I have a Console Application that needs to call an application.

Since I won’t be sure where it was installed, I need to assign the value to the path variable as below to get the application installation location.

string path = System.AppDomain.CurrentDomain.BaseDirectory + "IASD.ASCS.WPF.exe";

Now when I pass the parameter to open the application, the Application Console does not open the application.

Processe.Start (path); 

No error message is displayed. Only does not load the executable.

How to call this application when I don’t know where the executable was installed?

  • How does the path resultant?

  • 2

    It is recommended to concatenate paths using Path.Combine thus: Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "IASD.ASCS.WPF.exe")

  • 1

    They are inside a Try block catch, because if there is will give an error of O sistema não pode encontrar o arquivo especificado. To call this you have to pass the actual application path, or else add the path in windows environment variables, because, if you type like this Processe.Start ("calc.exe") it will open the calculator different from your system because it does not know the way... The System.AppDomain.CurrentDomain.BaseDirectory is referring to the execution path of your console application, and there should not have the executable that you seek

1 answer

1

If you want to launch the app from a specific location, then you need to know where it is.

I recommend not to put that location in your code but to use a configuration file. For example, use appSettings.

But if the location of the application is in the environment variable PATH, then it’s as simple as this:

Processe.Start("IASD.ASCS.WPF.exe");
  • I created a string variable and passed it the following value: String path = Path.Combine(System.AppDomain.Currentdomain.Basedirectory, "IASD.ASCS.WPF.exe"); when I call this variable: Process.Start(path); the executable is not loaded. Thank you

  • 1

    And does the executable exist in this path? Some exception is thrown?

  • Yes. I created two projects in the same Solution. I also created an installer with Inno setup for the application. In the installation directory are the files of both projects. If I put the full address of the executable, it works, but if I use Path.Combine(System.AppDomain.Currentdomain.Basedirectory, "IASD.ASCS.WPF.exe"); it doesn’t work.

  • 1

    If you set a complete path, it has to be the right one, obviously. When you install the application you could add the execution path to the PATH environment variable.

  • Even adding the path to PATH did not work. I think I need to load the executable by some other command. Would you have some other command in c# console application that loads applications?

  • If you execute this instruction var path = Environment.GetEnvironmentVariable("PATH") just before Processe.Start("IASD.ASCS.WPF.exe"), path contains the path to the executable?

  • In this example I need to pass the installation address and this I don’t have because the installer can change the installation directory.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.