How can I get path of setup.exe from custom action

2019-08-01 19:50发布

问题:

My setup.exe in e:\setup.exe, I tried this code:

System.AppDomain.CurrentDomain.BaseDirectory;

return c:\Windows\syswow64\

Application.ExecutablePath;

return c:\Windows\syswow64\MsiExec.exe

Application.StartupPath

return c:\Windows\syswow64\

I need something return e:\

回答1:

using System.IO;
string exeDir = Directory.GetCurrentDirectory();

You can get exe full path by reflection also.

string exeLocation = System.Reflection.Assembly.GetEntryAssembly().Location;

You can this too.

string exeDir = AppDomain.CurrentDomain.BaseDirectory;
string exeLocation = Assembly.GetEntryAssembly().Location;

One more way:

string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);


回答2:

To get current working directory use

Directory.GetCurrentDirectory();

which locate under System.IO