Alex Gordon
Alex Gordon

Reputation: 60691

getting location of installed application vb.net

i published an application in vb.net. the user will be able to install the application anywhere they choose on the computer (or perhaps not anywhere they choose but where ever the default location is). how can i programmatically get the location where the user installed the application? another words i need the application to know where it is running from. how do i detect that?

Upvotes: 3

Views: 5051

Answers (6)

Greg Bogumil
Greg Bogumil

Reputation: 1923

If you put this code in your exe then it will give you the path of the exe.

System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)

Upvotes: 3

Jim Counts
Jim Counts

Reputation: 12795

If your app is a Windows Forms app you can use the Application static class, as others have noted. For other kinds of applications, use reflection:

Dim a = System.Reflection.Assembly.GetEntryAssembly()
Dim location = a.Location

I had to do this the other day, works great.

Upvotes: 5

Jim
Jim

Reputation: 3665

Application.ExecutablePath 

that will tell you where your .exe is. Hope that helps.

Upvotes: 6

SLaks
SLaks

Reputation: 887215

Like this:

Shared ReadOnly AppDirectory As String = _
     Path.GetDirectoryName(New Uri(GetType(Program).Assembly.CodeBase).LocalPath)

Upvotes: 3

M.A. Hanin
M.A. Hanin

Reputation: 8074

In runtime, you can use:

Application.StartupPath

Upvotes: 9

Related Questions