Pobierz zainstalowane aplikacje w systemie

Jak zainstalować aplikacje w systemie za pomocą kodu c#?

Author: George Stocker, 2009-05-26

10 answers

Iteracja za pomocą klucza rejestru "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall" wydaje się dawać obszerną listę zainstalowanych aplikacji.

Oprócz poniższego przykładu, możesz znaleźć podobną wersję do tego, co zrobiłem tutaj.

To jest szorstki przykład, prawdopodobnie będziesz chciał zrobić coś, aby usunąć puste wiersze, jak w 2. linku podanym.

string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using(Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
{
    foreach(string subkey_name in key.GetSubKeyNames())
    {
        using(RegistryKey subkey = key.OpenSubKey(subkey_name))
        {
            Console.WriteLine(subkey.GetValue("DisplayName"));
        }
    }
}

Alternatywnie możesz użyć WMI, jak już wspomniano:

ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
foreach(ManagementObject mo in mos.Get())
{
    Console.WriteLine(mo["Name"]);
}

Ale to jest raczej wolniejszy w wykonaniu, a słyszałem, że może wyświetlać tylko programy zainstalowane pod "ALLUSERS", choć może to być nieprawidłowe. Ignoruje również komponenty i aktualizacje systemu Windows, które mogą być dla Ciebie przydatne.

 92
Author: Xiaofu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-05 18:00:14

Możesz rzucić okiem na Ten artykuł . Korzysta z rejestru, aby odczytać listę zainstalowanych aplikacji.

public void GetInstalledApps()
{
    string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
    using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
    {
        foreach (string skName in rk.GetSubKeyNames())
        {
            using (RegistryKey sk = rk.OpenSubKey(skName))
            {
                try
                {
                    lstInstalled.Items.Add(sk.GetValue("DisplayName"));
                }
                catch (Exception ex)
                { }
            }
        }
    }
}
 10
Author: Kirtan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-05-26 04:02:10

Warto zauważyć, że Klasa Win32_Product WMI reprezentuje produkty, ponieważ są one instalowane przez Instalator Windows [ http://msdn.microsoft.com/en-us/library/aa394378%28v=vs.85%29.aspx]. nie Każda aplikacja korzysta z Instalatora windows

Jednak "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" reprezentuje aplikacje dla 32 bitów. Dla 64 bitów musisz również przejść "HKEY_LOCAL_MACHINE \ SOFTWARE\Wow6432Node \ Microsoft \ Windows \ CurrentVersion\Uninstall" i ponieważ nie każdy oprogramowanie ma wersję 64-bitową, wszystkie zainstalowane aplikacje są połączeniem kluczy w obu lokalizacjach, które mają wartość" UninstallString " z nimi.

Ale najlepsze opcje pozostają takie same .traverse klucze rejestru jest lepszym podejściem, ponieważ każda aplikacja ma wpis w rejestrze[w tym te w Instalatorze Windows].jednak metoda rejestru jest niepewna, jak gdyby ktoś usuwa odpowiedni klucz, to nie będziesz znać wpisu aplikacji.Wręcz przeciwnie, zmieniając HKEY_Classes_ROOT \ Installers jest bardziej skomplikowane, ponieważ jest związane z problemami licencyjnymi, takimi jak Microsoft office lub inne produkty. dla bardziej solidne rozwiązanie zawsze można połączyć registry alternative z WMI.

 5
Author: Akshita,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-09-25 09:28:14

Zgadzam się, że wyliczanie za pomocą klucza rejestru jest najlepszym sposobem.

Należy jednak pamiętać, że klucz , @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", wyświetli listę wszystkich aplikacji w 32-bitowej instalacji Windows i 64-bitowych aplikacji w 64-bitowej instalacji Windows.

Aby zobaczyć również aplikacje 32-bitowe zainstalowane w 64-bitowej instalacji Windows, należy również wyliczyć klucz @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall".

 4
Author: Stephen Walter,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-05-19 04:31:55

Powtarzaj za pomocą kluczy" HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall "i sprawdź ich wartości "DisplayName".

 1
Author: Moayad Mardini,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-05-26 04:02:06

Czy Mogę zasugerować, aby spojrzeć na WMI (Narzędzia zarządzania Windows ). Jeśli dodasz System.Management reference do Twojego projektu C#, uzyskasz dostęp do klasy 'ManagementObjectSearcher', która prawdopodobnie okaże się przydatna.

Istnieją różne klasy WMI dla zainstalowanych aplikacji , ale jeśli została zainstalowana z Instalatorem Windows, Klasa Win32_Product jest prawdopodobnie najbardziej odpowiednia dla Ciebie.

ManagementObjectSearcher s = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
 1
Author: Nick,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-05-26 04:04:41

Użyj Windows Installer API!

Pozwala na rzetelne wyliczenie wszystkich programów. Rejestr nie jest wiarygodny, ale WMI jest ciężki.

 1
Author: Brian Haak,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-05 11:54:01

Użyłem podejścia Nicks - musiałem sprawdzić, czy zdalne narzędzia do Visual Studio są zainstalowane, czy nie, wydaje się to trochę powolne, ale w oddzielnym wątku to jest dla mnie w porządku. - tutaj mój Rozszerzony kod:

    private bool isRdInstalled() {
        ManagementObjectSearcher p = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
        foreach (ManagementObject program in p.Get()) {
            if (program != null && program.GetPropertyValue("Name") != null && program.GetPropertyValue("Name").ToString().Contains("Microsoft Visual Studio 2012 Remote Debugger")) {
                return true;
            }
            if (program != null && program.GetPropertyValue("Name") != null) {
                Trace.WriteLine(program.GetPropertyValue("Name"));
            }
        }
        return false;
    }
 1
Author: Marc Loeb,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-25 10:40:50

Najlepiej jest użyć WMI . W szczególności klasa Win32_Product .

 0
Author: paxdiablo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-05-26 03:58:58

Moim wymaganiem jest sprawdzenie, czy w moim systemie jest zainstalowane konkretne oprogramowanie. To rozwiązanie działa zgodnie z oczekiwaniami. To może Ci pomóc. Używałem aplikacji windows w c# z 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;

        }
 -1
Author: Pardha Saradhi Vanjarpau,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-06-21 15:54:00