You can use the following to get where the registry thinks it's installed:
(string)Registry.LocalMachine.GetValue(@"SOFTWARE\MyApplication\AppPath",
"Installed", null);
Or you can use the following to find out where the application is actually being launched from:
System.Windows.Forms.Application.StartupPath
The latter is more reliable than the former if you're trying to use the .exe
location as a relative path to find related files. The user could easily move things around after the install and still have the app work fine because .NET apps aren't so dependent upon the registry.
Using StartupPath
, you could even do something clever like have your app update the registry entries at run time instead of crashing miserably due to missing/wrong/corrupted entries.
And be sure to look at the app settings functionality as storage for values rather than the registry (Properties.Settings.Default.mySettingEtc
). You can read/write settings for the app and/or the user levels that get saved as simple MyApp.exe.config
files in standard locations. A nice blast from the past (good old Win 3.1/DOS days) to have the application install/delete be a simple copy/delete of a folder structure or two rather than some convoluted, arcane install/uninstall routine that leaves all kinds of garbage in the registry and sprinkled all over the hard drive.
MyApplication
is a Key andAppPath
is a Value. What you are asking is how to get the data associated withAppPath
.