Run an external exe using C # .NET.

I am running a process in C #, but I want to be able to do this without specifying a path. Where can I put an executable in a project so that the code detects that it does not indicate the path?

At the moment I have:

ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = @"C:\Docs\wkhtmltopdf.exe"; 

Which works fine, but I would like it to end:

  ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "wkhtmltopdf.exe"; 

I tried to place the EXE in a folder in the project, in the root of the project, in the bin folder of the project - all to no avail.

+1
source share
4 answers
 ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "wkhtmltopdf.exe"; psi.WorkingDirectory = Environment.CurrentDirectory; Process proc = Process.Start(psi); 
+6
source

I guess right now, but maybe it will be helfpul?

http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.workingdirectory.aspx

Just set this path to Environment.CurrentDirectory

+2
source

put the binary file whenever you want and add this folder to the% PATH% variable of the system

0
source

I would use one of Enviroment.SpecialFolders .

You can then infer the correct path without the need for hard coding any values ​​or requesting a request from the user.

0
source

All Articles