Parsi Coders
سورس کد بدست اورن لیست برنامه های نصب شده c# - نسخه قابل چاپ

+- Parsi Coders (http://parsicoders.com)
+-- انجمن: Software Development Programming (http://parsicoders.com/forumdisplay.php?fid=37)
+--- انجمن: C# Programming (http://parsicoders.com/forumdisplay.php?fid=55)
+--- موضوع: سورس کد بدست اورن لیست برنامه های نصب شده c# (/showthread.php?tid=1397)



سورس کد بدست اورن لیست برنامه های نصب شده c# - Amin_Mansouri - 12-30-2011

Instructions: 1. Add 'Using Microsoft.Win32' at the top of your code.
2. Put the following code into a class.
3. See example on using the code.

با سورس میتونید برنامه های که روی ویندوز نصب شده رو بدست اورید.

کد:
/// <summary>
        /// Gets a list of installed software and, if known, the software's install path.
        /// </summary>
        /// <returns></returns>
        private string Getinstalledsoftware()
        {
            //Declare the string to hold the list:
            string Software = null;

            //The registry key:
            string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
            using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
            {
                //Let's go through the registry keys and get the info we need:
                foreach (string skName in rk.GetSubKeyNames())
                {
                    using (RegistryKey sk = rk.OpenSubKey(skName))
                    {
                        try
                        {
                            //If the key has value, continue, if not, skip it:
                            if (!(sk.GetValue("DisplayName") == null))
                            {
                                //Is the install location known?
                                if (sk.GetValue("InstallLocation") == null)
                                    Software += sk.GetValue("DisplayName") + " - Install path not known\n"; //Nope, not here.
                                else
                                    Software += sk.GetValue("DisplayName") + " - " + sk.GetValue("InstallLocation") + "\n"; //Yes, here it is...
                            }
                        }
                        catch (Exception ex)
                        {
                            //No, that exception is not getting away... :P
                        }
                    }
                }
            }

            return Software;
        }


//EXAMPLE USAGE:
private void get_software_list_button__Click(object sender, EventArgs e)
        {
            MessageBox.Show(Getinstalledsoftware());
        }