1

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:\

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
Yaseen
  • 598
  • 6
  • 7
  • you can use `Directory.GetCurrentDirectory()` to get the current running process directory, you can also use `DriveInfo[] allDrives = DriveInfo.GetDrives();` to get all drives if that's what you are looking – inan Oct 20 '16 at 14:37
  • The problem is that, at the point at which your code is running, it's running as a component of an `.msi` file which, as most indications are telling you, is actually executed by the `MsiExec.exe` program. If there *is* a way to access this information, you'll be looking for something MSI specific for accessing MSI properties, not generic .NET code looking at the current executable/working directory. – Damien_The_Unbeliever Oct 20 '16 at 14:48

2 Answers2

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);
Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
  • thank you for your answer, some of your suggestions return path where the application will be after installation but one of them return path of setup.exe – Yaseen Oct 20 '16 at 14:56
  • That is why I have posted multiple answers, as it was not well explained in the question:) – Vivek Nuna Oct 20 '16 at 15:09
  • You can set the target path in CustomActionData property and get in context parameters also – Vivek Nuna Oct 20 '16 at 15:15
0

To get current working directory use

Directory.GetCurrentDirectory();

which locate under System.IO

Mostafiz
  • 7,243
  • 3
  • 28
  • 42