Get application installation path.

S

Shawn

I need to get the path to my program after it has been installed. In other
words, I want to be able to run a separate application that gets the path to
the other apps app.config file. This needs to work no matter where the user
installed the first app to and I would prefer to avoid looking at the
registry.

Thanks,
Shawn
 
F

Family Tree Mike

If these are two completely separate installations, then I think the easiest
way would be for application one to set up a well known registry key for it's
home location. The registry key will be read by application two to find the
config file.
 
K

kimiraikkonen

I need to get the path to my program after it has been installed. In other
words, I want to be able to run a separate application that gets the path to
the other apps app.config file. This needs to work no matter where the user
installed the first app to and I would prefer to avoid looking at the
registry.

Thanks,
Shawn

Hi Shawn,
If you want to get current working directory path of your application,
you can use:

My.Computer.Filesystem.CurrentDirectory

So, to get exact current path of your application, combine app's name
with folder's :

Dim currentfolder As String
currentfolder = My.Computer.Filesystem.CurrentDirectory

' Get full current path to your application
System.IO.Path.Combine(currentfolder,"appname.exe")


Hope this helps,

Onur Güzel
 
S

Shawn

Thanks for the reply, but I am trying to avoid the registry as I have read
that Microsoft will not support a registry in future releases (at least not
for sure) and for other reasons as well. Is there a way to do this through
WMI or something?
 
S

Shawn

Interesting, I will look at that... Thanks!!!

I need to get the path to my program after it has been installed. In other
words, I want to be able to run a separate application that gets the path
to
the other apps app.config file. This needs to work no matter where the
user
installed the first app to and I would prefer to avoid looking at the
registry.

Thanks,
Shawn

Hi Shawn,
If you want to get current working directory path of your application,
you can use:

My.Computer.Filesystem.CurrentDirectory

So, to get exact current path of your application, combine app's name
with folder's :

Dim currentfolder As String
currentfolder = My.Computer.Filesystem.CurrentDirectory

' Get full current path to your application
System.IO.Path.Combine(currentfolder,"appname.exe")


Hope this helps,

Onur Güzel
 
S

Shawn

Oh, but it may not be in the same path or even the same drive.

I need to get the path to my program after it has been installed. In other
words, I want to be able to run a separate application that gets the path
to
the other apps app.config file. This needs to work no matter where the
user
installed the first app to and I would prefer to avoid looking at the
registry.

Thanks,
Shawn

Hi Shawn,
If you want to get current working directory path of your application,
you can use:

My.Computer.Filesystem.CurrentDirectory

So, to get exact current path of your application, combine app's name
with folder's :

Dim currentfolder As String
currentfolder = My.Computer.Filesystem.CurrentDirectory

' Get full current path to your application
System.IO.Path.Combine(currentfolder,"appname.exe")


Hope this helps,

Onur Güzel
 
K

kimiraikkonen

Oh, but it may not be in the same path or even the same drive.

That's why .NET provides "CurrentDirectory" property to get whereever
your application is executed from.

I hope it works for you.

Thanks,

Onur Güzel
 
M

Martin H.

Hello Shawn,

You could create a file in the locale settings.

Option 1:
System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)

returns something like
C:\Documents and Settings\UserName\LocalSettings\Application Data

Option 2:
My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData

returns something like
C:\Documents and Settings\All Users\Application
Data\Company\Application\1.0.0.0

Option 3:
My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData

returns something like
C:\Documents and Settings\UserName\Application
Data\Company\Application\1.0.0.0

Please note that the paths mentioned here are from a Windows XP machine.
Under Vista they are different (C:\Users\ ... as far as I know).

I would use option 1 and then create my own subdirectory without the
version number as your other application would have to check any
possible directory name.

Best regards,

Martin
 
C

Cor Ligthert[MVP]

Hi Shawn,

In my idea is this the easiest one.

Application.StartupPath

Cor
 
F

Family Tree Mike

I think you are mistaken as to the registry going away, but I respect your
need to stay away from it as part of your requirements. Martin H. has the
next solution I would use with a persisted config in the local settings
folder.
 
D

dddd

Shawn said:
I need to get the path to my program after it has been installed. In other
words, I want to be able to run a separate application that gets the path to
the other apps app.config file. This needs to work no matter where the user
installed the first app to and I would prefer to avoid looking at the
registry.

Thanks,
Shawn
 
D

dddd

Shawn said:
I need to get the path to my program after it has been installed. In other
words, I want to be able to run a separate application that gets the path to
the other apps app.config file. This needs to work no matter where the user
installed the first app to and I would prefer to avoid looking at the
registry.

Thanks,
Shawn
 
D

dddd

Shawn said:
I need to get the path to my program after it has been installed. In other
words, I want to be able to run a separate application that gets the path to
the other apps app.config file. This needs to work no matter where the user
installed the first app to and I would prefer to avoid looking at the
registry.

Thanks,
Shawn
 
P

Phill W.

dddd said:
I need to get the path to my program after it has been installed.

There are other ways but I tend to use:

System.Reflection.Assembly.GetEntryAssembly().Location
In other words, I want to be able to run a separate application
that gets the path to the other apps app.config file.

Now /that's/ not so simple.

You're going to have to persist the installed location somewhere outside
of both programs. The Registry is quick and easy and there /is/ plenty
of precedent for using it (see below).

However, even if you can /get/ to that file, what are you hoping to /do/
with it? You may hit problems trying to access or update the file.
This needs to work no matter where the user installed the first app
to and I would prefer to avoid looking at the registry.

You might prefer to avoid it (I'm getting there myself, to be honest)
but this is actually one of the Good Reasons for using the Registry;
it's where applications have "published" their installed locations for
years. Have a look under ...

HKLM\Software\Microsoft\WindowsCurrentVersion\App Paths

.... and you'll find just about everything that you can start by

Start > Run ...

Not such a bad place to add your own entry, perhaps?

If you /really/ don't want to use the Registry, then you're probably
looking at writing a file somewhere under the "All Users/Application
Data" sub-tree in the file system.
However, if you were avoiding the Registry for security reasons, then
you'll probably face the /same/ problems trying to update these
directories as well - "regular" [Vista] Users won't be able to update
this area so you'll have to create an "installer" for your programs.

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top