aboutsummaryrefslogtreecommitdiff
path: root/src/test/burn/WixTestTools/MsiUtilities.cs
blob: 4c7d160131be6324ca710c58371359009c81cda5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixTestTools
{
    using System;
    using WixToolset.Dtf.WindowsInstaller;

    public class MsiUtilities
    {
        /// <summary>
        /// Return true if it finds the given productcode in system otherwise it returns false
        /// </summary>
        /// <param name="prodCode"></param>
        /// <returns></returns>
        public static bool IsProductInstalled(string prodCode)
        {
            //look in all user's products (both per-machine and per-user)
            foreach (ProductInstallation product in ProductInstallation.GetProducts(null, "s-1-1-0", UserContexts.All))
            {
                if (product.ProductCode == prodCode)
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// Return true if it finds the given productcode in system with the specified version otherwise it returns false
        /// </summary>
        /// <param name="prodCode"></param>
        /// <param name="prodVersion"></param>
        /// <returns></returns>
        public static bool IsProductInstalledWithVersion(string prodCode, Version prodVersion)
        {
            //look in all user's products (both per-machine and per-user)
            foreach (ProductInstallation product in ProductInstallation.GetProducts(null, "s-1-1-0", UserContexts.All))
            {
                if (product.ProductCode == prodCode && product.ProductVersion == prodVersion)
                {
                    return true;
                }
            }
            return false;
        }
    }
}