Get installed applications in a system

后端 未结 14 1145
遥遥无期
遥遥无期 2020-11-22 08:28

How to get the applications installed in the system using c# code?

14条回答
  •  Happy的楠姐
    2020-11-22 09:31

    My requirement is to check if specific software is installed in my system. This solution works as expected. It might help you. I used a windows application in c# with visual studio 2015.

     private void Form1_Load(object sender, EventArgs e)
            {
    
                object line;
                string softwareinstallpath = string.Empty;
                string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
                using (var baseKey = Microsoft.Win32.RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
                {
                    using (var key = baseKey.OpenSubKey(registry_key))
                    {
                        foreach (string subkey_name in key.GetSubKeyNames())
                        {
                            using (var subKey = key.OpenSubKey(subkey_name))
                            {
                                line = subKey.GetValue("DisplayName");
                                if (line != null && (line.ToString().ToUpper().Contains("SPARK")))
                                {
    
                                    softwareinstallpath = subKey.GetValue("InstallLocation").ToString();
                                    listBox1.Items.Add(subKey.GetValue("InstallLocation"));
                                    break;
                                }
                            }
                        }
                    }
                }
    
                if(softwareinstallpath.Equals(string.Empty))
                {
                    MessageBox.Show("The Mirth connect software not installed in this system.")
                }
    
    
    
                string targetPath = softwareinstallpath + @"\custom-lib\";
                string[] files = System.IO.Directory.GetFiles(@"D:\BaseFiles");
    
                // Copy the files and overwrite destination files if they already exist. 
                foreach (var item in files)
                {
                    string srcfilepath = item;
                    string fileName = System.IO.Path.GetFileName(item);
                    System.IO.File.Copy(srcfilepath, targetPath + fileName, true);
                }
                return;
    
            }
    

提交回复
热议问题