Alex Rivera | Logout

How to get installation path of an application?

Asked 2009-05-26T09:27:00.843
14

In Windows using C#, how can I get the installation path of a software (for example consider NUnit or any other software like MS word, etc.) from my project? Also how to set the path variables that we set in Environment variables so that we can run the application just by giving in command prompt.

Like if I install NUnit in "C:\Program Files" I can run it by giving 'NUnit' in cmd prompt but if I install in a different location I can't do the same. I need to get the location or path of NUnit or any other software installed in my system (having Windows XP) from my project.

EDIT: Like I can get the path of installed program from registry. HKEY_CURRENT_USER->SOFTWARE

Edit
Report

2 Answers

9
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.

answered 2009-05-26T09:46:31.257
2

Application.StartupPath is used to get installation location in c#.

answered 2009-05-26T09:46:42.253

Your Answer