Developer

Locate the executable path using VB.NET

In this Visual Basic .NET tip, Irina Medvinskaya looks at a simple way to determine the path where the current executable resides.

It is often useful to be able to determine the path where the current executable resides. A simple way to do this using Visual Basic .NET is to read the value of the StartUpPath property of the Application class. This can also be achieved by determining the current working path or utilizing reflection to determine the code base location of the currently executing assembly.

Example

In order to demonstrate finding the executable path, add the listbox control ListBox1 to the form and add the code in Listing A. (Note: You must use theSystem.Windows.Forms namespace to use the technique in this example.) When you run the code, your result will look like Figure 1.

In this example, I utilize the System.Windows.Forms namespace and initially get the ExecutablePath property of the Application class. The value is displayed in ListBox1. Then, I get the StartUpPath property of the Application class and also display it in ListBox1.

Miss a tip?

Check out the Visual Basic archive, and catch up on the most recent editions of Irina Medvinskaya's column.

Advance your scripting skills to the next level with TechRepublic's free Visual Basic newsletter, delivered each Friday. Automatically sign up today!

Editor's Picks