Reputation: 60691
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
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
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
Reputation: 166326
You can have a look at
Application.ExecutablePath Property
or
AppDomain.BaseDirectory Property
Upvotes: 3
Reputation: 3665
Application.ExecutablePath
that will tell you where your .exe is. Hope that helps.
Upvotes: 6
Reputation: 887215
Like this:
Shared ReadOnly AppDirectory As String = _
Path.GetDirectoryName(New Uri(GetType(Program).Assembly.CodeBase).LocalPath)
Upvotes: 3