Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of App.Path and App.EXEName in VB.Net

Tags:

.net

vb.net

I need some help to find the equivalent of App.Path and App.EXEName in VB.Net in a DLL.

Thank you for your help.

like image 906
remy_jourde Avatar asked Feb 06 '12 16:02

remy_jourde


1 Answers

According to MSDN (App Object Changes in Visual Basic .NET), the replacement for both is

System.Reflection.Assembly.GetExecutingAssembly().Location

It contains the full path (App.Path) as well as the file name (App.EXEName). You can split the information using the helper methods from the Path class:

' Import System.Reflection and System.IO at the top of your class file
Dim location = Assembly.GetExecutingAssembly().Location
Dim appPath = Path.GetDirectoryName(location)       ' C:\Some\Directory
Dim appName = Path.GetFileName(location)            ' MyLibrary.DLL

UPDATE (thanks to the commenters): If you are executing this code in a DLL and you want the name of the EXE that called the DLL, you need to use GetEntryAssembly instead of GetExecutingAssembly. Note that GetEntryAssembly might return Nothing if your DLL was called from an unmanaged EXE.

like image 193
Heinzi Avatar answered Oct 01 '22 23:10

Heinzi