O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Get the Executable Path

Problem

You want to retrieve the path where the current executable is stored.

Solution

Read the shared StartupPath property of the System.Windows.Forms.Application class.

Discussion

The System.Windows.Forms.Application class allows you to retrieve the directory where the executable is stored, even if it isn’t a Windows application.

Console.Write("Executable is: ")
Console.WriteLine(System.Windows.Forms.Application.ExecutablePath)
Console.Write("Executable is executing in: ")
Console.WriteLine(System.Windows.Forms.Application.StartupPath)

In order to use this technique, you must reference the System. Windows.Forms namespace. Alternatively, you can simply find the current working path (using recipe Set the Current Working Path

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required