Get installed applications in a system

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

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

14条回答
  •  臣服心动
    2020-11-22 09:22

    The object for the list:

    public class InstalledProgram
    {
        public string DisplayName { get; set; }
        public string Version { get; set; }
        public string InstalledDate { get; set; }
        public string Publisher { get; set; }
        public string UnninstallCommand { get; set; }
        public string ModifyPath { get; set; }
    }
    

    The call for creating the list:

        List installedprograms = new List();
        string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
        {
            foreach (string subkey_name in key.GetSubKeyNames())
            {
                using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                {
                    if (subkey.GetValue("DisplayName") != null)
                    {
                        installedprograms.Add(new InstalledProgram
                        {
                            DisplayName = (string)subkey.GetValue("DisplayName"),
                            Version = (string)subkey.GetValue("DisplayVersion"),
                            InstalledDate = (string)subkey.GetValue("InstallDate"),
                            Publisher = (string)subkey.GetValue("Publisher"),
                            UnninstallCommand = (string)subkey.GetValue("UninstallString"),
                            ModifyPath = (string)subkey.GetValue("ModifyPath")
                        });
                    }
                }
            }
        }
    

提交回复
热议问题