How to get installation path of an application?

string appFileName = Environment.GetCommandLineArgs()[0];

will give you the full path of the executable and

string directory = Path.GetDirectoryName(appFileName);

extracts the directory.

string envPath = Environment.GetEnvironmentVariable("PATH");
Environment.SetEnvironmentVariable(envPath + ";" + yourPath); 

edits the PATH environment variable for the current process.


Use the system and application classes. This will give you all sorts of information.

EG: Application.ExecutablePath

It also provides methods to do what you want to.

Edit: Also see registry read/write instructions here:

http://www.c-sharpcorner.com/UploadFile/sushmita_kumari/RegistryKeys102082006061720AM/RegistryKeys1.aspx?ArticleID=0ce07333-c9ab-4a6a-bc5d-44ea2523e232


Application.ExecutablePath (includes filename)
Application.StartupPath (not includes filename)

This will give you the path where the application started. Hopefully it will be the installation path.

Tags:

Windows

C#