Get Application Startup and Executable Path in VB.NET

The code snippet in this article demonstrates how to use Application class static properties to get Windows Forms application startup path, executable path and user data path using VB.NET.
  • 25051

Application Path

CommonPathAppData property returns the path for the application data that is shared among all users. If a path does not exist, the default created path format is Base Path\CompanyName\ProductName\ProductVersion.

UserAppDataPath property returns the path for the application data of a user. If a path does not exist, the default created path format is Base Path\CompanyName\ProductName\ProductVersion.

LocalUserAppDataPath property returns the path for the application data of a local user. If a path does not exist, the default created path format is Base Path\CompanyName\ProductName\ProductVersion.

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.

CommonAppDataRegistry property returns the registry key for the application data that is shared among all users.

AllowQuit property returns true if the caller can quit the current application.

The C# code snippet in Listing 1 uses the above discussed properties to add the values of these properties to a ListBox control on a Form.  

listBox1.Items.Add("CommonAppDataPath: " + Application.CommonAppDataPath);

listBox1.Items.Add("CommonAppDataRegistry: " + Application.CommonAppDataRegistry.ToString());

listBox1.Items.Add("ExecutablePath: " + Application.ExecutablePath);

listBox1.Items.Add("LocalUserAppDataPath: " + Application.LocalUserAppDataPath);

listBox1.Items.Add("StartupPath: " + Application.StartupPath);

listBox1.Items.Add("UserAppDataPath: " + Application.UserAppDataPath);

 

Listing 2

The output of Listing 2 looks like Figure 2.

 

AppPathImg.jpg
 

Figure 2

Listing 3 is the VB.NET version of Listing 2.

listBox1.Items.Add("CommonAppDataPath: " + Application.CommonAppDataPath)

listBox1.Items.Add("CommonAppDataRegistry: " + Application.CommonAppDataRegistry.ToString())

listBox1.Items.Add("ExecutablePath: " + Application.ExecutablePath)

listBox1.Items.Add("LocalUserAppDataPath: " + Application.LocalUserAppDataPath)

listBox1.Items.Add("StartupPath: " + Application.StartupPath)

listBox1.Items.Add("UserAppDataPath: " + Application.UserAppDataPath)

 

Listing 3

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.