Question

I'm making a C# program and I need to find installation paths of some software that is installed on a computer. What I have to work with is, I have the Program's name (e.g. Google Chrome), i have the process name (e.g. Chrome.exe). What I need now is the path to Chrome.exe. How can i use C# to find the path if i was to pass either the program name or process name as a parameter for the search? Actually I want to make a custom action which will find chrome.exe and invoke a link. After that I will use the path for search chrome.exe and I want to default open a website via chrome. What should I do..?

Was it helpful?

Solution

Another option to consider is just launching the link using Process.Start() and letting the operating system use the default browser to open the link. That would likely be more what the user would expect.

In the WiX toolset, you can get that behavior for free using ShellExecute standard custom action from the WixUtilExtension.

OTHER TIPS

You could try something like this

public string GetProcessPath(string name)
{
 Process[] processes = Process.GetProcessesByName(name);

 if (processes.Length > 0)
 {
    return processes[0].MainModule.FileName;
 }
 else
 {
    return string.Empty;
 }
}

or you could use Linq

or you could do what you do but use linq

     Process element = ( from p in Process.GetProcesses()
                where p.ProcessName == "Chrome.exe"
                select p ).FirstOrDefault( );

However there can be multiple process with same name .So you have to further modify the code according to your requirement.

hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top