Get launch path in vb.net exe console

How to get the starting path (system.windows.forms.application.StartupPath) of my exe without adding a link to system.windows.forms?

+4
source share
3 answers

You can try

System.AppDomain.CurrentDomain.BaseDirectory 

which will work in most cases.

+15
source

EDIT: @KiwiBastard's answer is the correct method:

 System.AppDomain.CurrentDomain.BaseDirectory 

Add a link to System.Reflection and use

 Assembly.GetExecutingAssembly().Location 

EDIT: depending on where you are going to get the start path, this might be more appropriate:

 Assembly.GetEntryAssembly().Location 
+4
source

You can get the start path without reflection using:

 IO.Path.GetDirectoryName(Diagnostics.Process.GetCurrentProcess().MainModule.FileName) 
+3
source

All Articles