View difference between Paste ID: geyckhLW and Ca62V5V2
SHOW: | | - or go back to the newest paste.
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading;
6
using Microsoft.Deployment.WindowsInstaller;
7
using Microsoft.Deployment.WindowsInstaller.Linq;
8
using Microsoft.Deployment.WindowsInstaller.Linq.Entities;
9
using Microsoft.Deployment.WindowsInstaller.Package;
10
11
namespace MSI_Mgmt
12
{
13
    class Program
14
    {
15
        static void Main(string[] args)
16
        {
17
            Installer.SetInternalUI(InstallUIOptions.Silent);
18
            Console.WriteLine("List Installed Applications\n");
19
            IOrderedEnumerable<ProductInstallation> ap = ProductInstallation.AllProducts.OrderBy(pi => pi.Publisher)
20
                .ThenBy(pi => pi.ProductName)
21
                .ThenBy(pi => pi.Features.Where(f => f.FeatureName == "ProductFeature").Select(f => f.FeatureName).SingleOrDefault())
22
                .ThenBy(pi => pi.ProductVersion);
23
            foreach (ProductInstallation pi in ap.ToArray())
24-
                if (pi.Publisher == "Microsoft Corporation") continue;
24+
25
                //break;
26
                /*if (pi.Publisher == "Microsoft Corporation") continue;
27
                if (pi.Publisher == "Microsoft Corporations") continue;
28
                if (pi.Publisher == "Microsoft") continue;
29
                if (pi.Publisher == "Microsoft Garage") continue;
30
                if (pi.Publisher == ".NET Foundation") continue;
31
                if (pi.Publisher == "Adobe Systems Incorporated") continue;
32
                if (pi.Publisher == "Adobe Systems, Inc") continue;
33
                if (pi.Publisher == "Apple Inc.") continue;
34
                if (pi.Publisher == "CyberLink Corp.") continue;
35
                if (pi.Publisher == "Dell Products, LP") continue;
36
                if (pi.Publisher == "Dell") continue;
37
                if (pi.Publisher == "Dell Inc.") continue;
38
                if (pi.Publisher == "Intel") continue;
39
                if (pi.Publisher == "INTEL") continue;
40
                if (pi.Publisher == "Intel Corporation") continue;
41
                if (pi.Publisher == "Google") continue;
42
                if (pi.Publisher == "Google Inc") continue;
43
                if (pi.Publisher == "Google LLC") continue;
44
                if (pi.Publisher == "Google, Inc.") continue;
45
                if (pi.Publisher == "Oracle Corporation") continue;
46
                if (pi.Publisher == "Plex") continue;
47
                if (pi.Publisher == "Plex, Inc.") continue;
48
                if (pi.Publisher == "Python Software Foundation") continue;
49
                if (pi.Publisher == "MariaDB Corporation Ab") continue;
50
                if (pi.Publisher == "The Document Foundation") continue;
51-
                if (pi.Publisher == "pdfforge GmbH") continue;
51+
52-
                if (String.IsNullOrEmpty(pi.Publisher) && String.IsNullOrEmpty(pi.ProductName) && pi.ProductVersion == null) continue;
52+
53
                if (pi.Publisher == "pdfforge GmbH") continue;//*/
54
                //if (String.IsNullOrEmpty(pi.Publisher) && String.IsNullOrEmpty(pi.ProductName) && pi.ProductVersion == null) continue;
55
                foreach(FeatureInstallation fi in pi.Features) {
56
                    Console.WriteLine("{0} = {1} - ({2})", fi.FeatureName, fi.State.ToString(), fi.Usage.UseCount);
57
                }
58
                //break;
59
                Session s = null;
60
                String p = pi.LocalPackage;
61
                String f = "";
62
                String u = "";
63
                if (pi.LocalPackage != null && pi.LocalPackage.Length>0)
64-
                        s = Installer.OpenPackage(pi.LocalPackage, true);
64+
65
                    try
66
                    {
67
                        s = Installer.OpenPackage(p, true);
68-
                        String p = pi.LocalPackage.ToLower().Replace("c:\\windows\\installer\\", "D:\\Installer-Backup\\");
68+
69
                    catch(InstallerException e)
70
                    {
71
                        p = pi.LocalPackage.ToLower().Replace("c:\\windows\\installer\\", "D:\\Installer-Backup\\");
72
                        s = Installer.OpenPackage(p, true);
73
                    }
74-
                        f = s.Features.Where(fs => fs.Name == "ProductFeature").Single().Title;
74+
75
                    f = s.Features.Where(fs => fs.Name == "ProductFeature").Select(fs => fs.Title).SingleOrDefault();
76-
                    catch(Exception e)
76+
77
                    {
78-
                        f = "";
78+
79
                    }
80
                    s.Close();
81
                }
82
                try
83
                {
84
                    if(String.IsNullOrEmpty(f)) f = pi.Features.Where(fs => fs.FeatureName == "ProductFeature").Single().GetHashCode().ToString();
85
                }
86
                catch(Exception e)
87
                {
88
                    f = "";
89
                }
90
                Console.WriteLine("{0} - {1} - {2} - {3} - {4} ({5})", pi.Publisher, pi.ProductName, f, pi.AdvertisedLanguage, pi.ProductVersion, pi.IsInstalled);
91
                Console.WriteLine("{0} {1} {2}", pi.ProductCode, pi.AdvertisedPackageCode, u);
92
                Console.WriteLine("{0}", p);
93
                Console.ReadLine();
94
                Console.WriteLine();
95
            }
96
97
            Console.WriteLine("List Installed Patches\n");
98
99
            foreach (PatchInstallation pi in PatchInstallation.AllPatches)
100
            {
101
                Console.WriteLine("{0} - {1} - {2} - {3} - {4} -- {5} - {6}", pi.LocalPackage, pi.ProductCode, pi.PatchCode, pi.DisplayName, pi.IsInstalled,
102
                    pi.SourceList.PackageName, pi.SourceList.LastUsedSource);
103
                //pi.SourceList.MediaPackagePath, "");
104
                //String.Join("@", pi.SourceList.MediaList.Select(md => md.VolumeLabel).ToArray())
105
                Console.WriteLine();
106
            }
107
108
            
109
            //Thread.Sleep(10000);
110
            Console.ReadLine();
111
        }
112
    }
113
}