none
how to fetch Install location of products from registry? RRS feed

  • Question

  • Hi all 
    i want to fetch install location of all products in my app so for that purpose i am using registry class and using below string value for it
    "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\UnInstall"
    and
    "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\UnInstall" for 64 bit version.
    but it is not giving me details of all products for example
    notepad ++ available in above path in registry editor but using my code it is not displaying the values for notepad.

      StreamWriter sw = new StreamWriter(@"D:\localmachineProducts64.txt", true);
                using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
                {
                    foreach (string skName in rk.GetSubKeyNames())
                    {
                        using (RegistryKey sk = rk.OpenSubKey(skName))
                        {
                            try
                            {
                                sw.Write(sk.GetValue("DisplayName") + "\t" + sk.GetValue("InstallLocation"));
                                sw.Write(sw.NewLine);
                                count++;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                        }
                    }
                    sw.Write("Total count  :=" + count);
                }
                sw.Close();


    sumitk

    Saturday, December 2, 2017 2:27 PM

All replies

  • You can use the Shell and PKEY_Software_InstallLocation to get the path (can be blank like in "Programs and Features" window)
    Saturday, December 2, 2017 2:45 PM
  • Hello sumitk,

    If you just want to obtain the program's install location, the below registry path is good choice for you. Most of all program you will find the path except free-installation programs.

    SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\

    The following is a simple example and of course it  includes notepad++ information.

                RegistryKey localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
                localKey = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\", true);
                foreach (string skName in localKey.GetSubKeyNames())
                {
                    using (RegistryKey sk = localKey.OpenSubKey(skName))
                    {
                        try
                        {
                            Console.WriteLine(skName);
                            Console.WriteLine("Default" + sk.GetValue(null));
                            Console.WriteLine(sk.GetValue("Path") + "\t");
          
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 4, 2017 10:05 AM
    Moderator
  • Hello Sumitk.cdac,

    Do you have anything to update? If the issue has been solved, you could mark the helpful reply as answer. This can be beneficial to other community members reading this thread. Thanks a lot.

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Sunday, December 24, 2017 6:23 AM
    Moderator