You can use the following to find out where the registry thinks it is installed:
(string)Registry.LocalMachine.GetValue(@"SOFTWARE\MyApplication\AppPath", "Installed", null);
Or you can use the following to find out where the application actually starts:
System.Windows.Forms.Application.StartupPath
The latter is more reliable than the first if you are trying to use the .exe location as a relative path to search for related files. The user can easily move things after installation and still work in the application, because .NET applications are not so dependent on the registry.
Using StartupPath , you can even do something smart, as if your application was updating registry entries at runtime rather than failing due to missing / incorrect / corrupted entries.
And do not forget to look at the settings of the application, as a storage of values, and not on the registry ( Properties.Settings.Default.mySettingEtc ). You can read / write settings for applications and / or user levels, which are saved as simple MyApp.exe.config files in standard places. A good take-off from the past (the good old days of Win 3.1 / DOS) for installing / uninstalling an application is a simple copy / uninstall of a folder structure or two, and not some confusing, secret installation / uninstallation procedure that leaves all kinds of garbage in the registry and sprinkled on the entire hard drive.
BH 04 Oct 2018-12-12T00: 00Z
source share