Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the startup path in a vb.net console exe

Tags:

io

vb.net

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

like image 704
wusher Avatar asked Nov 18 '08 23:11

wusher


People also ask

What is application StartupPath?

StartupPath property returns the path for the executable file that started the application, not the path where the application executable is stored. ExecutablePath property returns the path for the executable file that started the application, including the executable name.

Where does the name of the application appear in VB net?

Where did the name of the application appear in VB net? At the top of the form there is a title bar which displays the forms title. Form1 is the default name, you can change the name to your convenience . The title bar also includes the control box, which holds the minimize, maximize, and close buttons.


3 Answers

You could try

System.AppDomain.CurrentDomain.BaseDirectory

which would work for most cases.

like image 117
JamesSugrue Avatar answered Oct 08 '22 16:10

JamesSugrue


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

System.AppDomain.CurrentDomain.BaseDirectory

Add a reference to System.Reflection and use

Assembly.GetExecutingAssembly().Location

EDIT: Depending where you intend getting the startup path, this might be more appropriate:

Assembly.GetEntryAssembly().Location
like image 42
Mitch Wheat Avatar answered Oct 08 '22 18:10

Mitch Wheat


You can get the startup path without reflection by using:

IO.Path.GetDirectoryName(Diagnostics.Process.GetCurrentProcess().MainModule.FileName)
like image 45
Andrew Moore Avatar answered Oct 08 '22 18:10

Andrew Moore