Exemplo n.º 1
0
		private DataView GetProductData(string productCode)
		{
			DataTable table = new DataTable("ProductProperties");
			table.Locale = CultureInfo.InvariantCulture;
			table.Columns.Add("ProductPropertiesProperty", typeof(string));
			table.Columns.Add("ProductPropertiesValue", typeof(string));

			// Add a fake "ProductCode" install property, just for display convenience.
			table.Rows.Add(new object[] { "ProductCode", productCode });

            ProductInstallation product = new ProductInstallation(productCode);

			foreach(string property in new string[]
			{
				"AssignmentType",
				"DiskPrompt",
				"HelpLink",
				"HelpTelephone",
				"InstalledProductName",
				"InstallDate",
				"InstallLocation",
				"InstallSource",
				"Language",
				"LastUsedSource",
				"LastUsedType",
				"LocalPackage",
				"MediaPackagePath",
				"PackageCode",
				"PackageName",
				"ProductIcon",
				"ProductID",
				"ProductName",
				"Publisher",
				"RegCompany",
				"RegOwner",
				"State",
				"transforms",
				"Uninstallable",
				"UrlInfoAbout",
				"UrlUpdateInfo",
				"Version",
				"VersionMinor",
				"VersionMajor",
				"VersionString"
			})
			{
				try
				{
                    string value = product[property];
					table.Rows.Add(new object[] { property,  (value != null ? value : "") });
				}
				catch(InstallerException iex)
				{
					table.Rows.Add(new object[] { property, iex.Message });
				}
				catch(ArgumentException) { }
			}
			return new DataView(table, "", "ProductPropertiesProperty ASC", DataViewRowState.CurrentRows);
		}
Exemplo n.º 2
0
        /// <summary>
        /// Detects the state of the feature.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        static InstallState DetectFeatureState(Session session, string name)
        {
            var productCode = session["ProductCode"];

            var installedPackage = new Microsoft.Deployment.WindowsInstaller.ProductInstallation(productCode);

            if (installedPackage.IsInstalled)
            {
                return(installedPackage.Features
                       .First(x => x.FeatureName == name)
                       .State);
            }
            else
            {
                return(InstallState.Absent);
            }
        }
Exemplo n.º 3
0
 public static string GetProductName(string productCode)
 {
     string productName = (string) productCodesToNames[productCode];
     if(productName == null)
     {
         productName = new ProductInstallation(productCode).ProductName;
         productName = productName.Replace('\\', ' ');
         if(productNamesToCodes.Contains(productName))
         {
             string modifiedProductName = null;
             for(int i = 2; i < Int32.MaxValue; i++)
             {
                 modifiedProductName = productName + " [" + i + "]";
                 if(!productNamesToCodes.Contains(modifiedProductName)) break;
             }
             productName = modifiedProductName;
         }
         productCodesToNames[productCode] = productName;
         productNamesToCodes[productName] = productCode;
     }
     return productName;
 }
Exemplo n.º 4
0
        //[Fact]
        public void FeaturesAPI()
        {
            //var installedPackage = new Microsoft.Deployment.WindowsInstaller.ProductInstallation("{A6801CC8-AC2A-4BF4-BEAA-6EE4DCF17056}");
            var installedPackage = new Microsoft.Deployment.WindowsInstaller.ProductInstallation("A6801CC8-AC2A-4BF4-BEAA-6EE4DCF17056");

            if (!installedPackage.IsInstalled)
            {
            }
            else
            {
                foreach (var currentInstallFeature in installedPackage.Features)
                {
                    if (currentInstallFeature.State == InstallState.Local)
                    {
                        Debug.WriteLine(string.Format("Migrating feature {0} - marking as Present", currentInstallFeature.FeatureName));
                    }
                    else
                    {
                        Debug.WriteLine(string.Format("Migrating feature {0} - marking as Absent", currentInstallFeature.FeatureName));
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void InstallerTransactTwoProducts()
        {
            string dbFile1 = "InstallerTransactProduct1.msi";
            string dbFile2 = "InstallerTransactProduct2.msi";
            string productCode1;
            string productCode2;

            using (Database db1 = new Database(dbFile1, DatabaseOpenMode.CreateDirect))
            {
                WindowsInstallerUtils.InitializeProductDatabase(db1);
                WindowsInstallerUtils.CreateTestProduct(db1);

                productCode1 = db1.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0];

                db1.Commit();
            }

            using (Database db2 = new Database(dbFile2, DatabaseOpenMode.CreateDirect))
            {
                WindowsInstallerUtils.InitializeProductDatabase(db2);
                WindowsInstallerUtils.CreateTestProduct(db2);

                productCode2 = db2.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0];

                db2.Commit();
            }

            ProductInstallation installation1 = new ProductInstallation(productCode1);
            ProductInstallation installation2 = new ProductInstallation(productCode2);
            Assert.IsFalse(installation1.IsInstalled, "Checking that product 1 is not installed before starting.");
            Assert.IsFalse(installation2.IsInstalled, "Checking that product 2 is not installed before starting.");

            Installer.SetInternalUI(InstallUIOptions.Silent);
            ExternalUIHandler prevHandler = Installer.SetExternalUI(WindowsInstallerTest.ExternalUILogger,
                InstallLogModes.FatalExit |
                InstallLogModes.Error |
                InstallLogModes.Warning |
                InstallLogModes.User |
                InstallLogModes.Info |
                InstallLogModes.ResolveSource |
                InstallLogModes.OutOfDiskSpace |
                InstallLogModes.ActionStart |
                InstallLogModes.ActionData |
                InstallLogModes.CommonData |
                InstallLogModes.Progress |
                InstallLogModes.Initialize |
                InstallLogModes.Terminate |
                InstallLogModes.ShowDialog);
            Assert.IsNull(prevHandler, "Checking that returned previous UI handler is null.");

            Transaction transaction = new Transaction("TestInstallTransaction", TransactionAttributes.None);

            Exception caughtEx = null;
            try
            {
                Installer.InstallProduct(dbFile1, String.Empty);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Exception thrown while installing product 1: " + caughtEx);

            Console.WriteLine();
            Console.WriteLine("===================================================================");
            Console.WriteLine();

            try
            {
                Installer.InstallProduct(dbFile2, String.Empty);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Exception thrown while installing product 2: " + caughtEx);

            transaction.Commit();
            transaction.Close();

            prevHandler = Installer.SetExternalUI(prevHandler, InstallLogModes.None);
            Assert.AreEqual<ExternalUIHandler>(WindowsInstallerTest.ExternalUILogger, prevHandler, "Checking that previously-set UI handler is returned.");

            Assert.IsTrue(installation1.IsInstalled, "Checking that product 1 is installed.");
            Assert.IsTrue(installation2.IsInstalled, "Checking that product 2 is installed.");

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("===================================================================");
            Console.WriteLine("===================================================================");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            ExternalUIRecordHandler prevRecHandler = Installer.SetExternalUI(WindowsInstallerTest.ExternalUIRecordLogger,
                InstallLogModes.FatalExit |
                InstallLogModes.Error |
                InstallLogModes.Warning |
                InstallLogModes.User |
                InstallLogModes.Info |
                InstallLogModes.ResolveSource |
                InstallLogModes.OutOfDiskSpace |
                InstallLogModes.ActionStart |
                InstallLogModes.ActionData |
                InstallLogModes.CommonData |
                InstallLogModes.Progress |
                InstallLogModes.Initialize |
                InstallLogModes.Terminate |
                InstallLogModes.ShowDialog);
            Assert.IsNull(prevRecHandler, "Checking that returned previous UI record handler is null.");

            transaction = new Transaction("TestUninstallTransaction", TransactionAttributes.None);

            try
            {
                Installer.InstallProduct(dbFile1, "REMOVE=All");
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Exception thrown while removing product 1: " + caughtEx);

            try
            {
                Installer.InstallProduct(dbFile2, "REMOVE=All");
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Exception thrown while removing product 2: " + caughtEx);

            transaction.Commit();
            transaction.Close();

            Assert.IsFalse(installation1.IsInstalled, "Checking that product 1 is not installed after removing.");
            Assert.IsFalse(installation2.IsInstalled, "Checking that product 2 is not installed after removing.");

            prevRecHandler = Installer.SetExternalUI(prevRecHandler, InstallLogModes.None);
            Assert.AreEqual<ExternalUIRecordHandler>(WindowsInstallerTest.ExternalUIRecordLogger, prevRecHandler, "Checking that previously-set UI record handler is returned.");
        }
 public ProductInstallationWrap(ProductInstallation underlyaingObject)
 {
     _underlyaingObject = underlyaingObject;
  
 }
Exemplo n.º 7
0
        public void Burn_ValidateMultipleSourcePaths()
        {
            // Build the package.
            string packageA = this.GetPackageA().Output;
            string packageA_Directory = Path.GetDirectoryName(packageA);
            string packageA_ProductCode = MsiUtils.GetMSIProductCode(packageA);

            // Build the bundle.
            string bundleA = this.GetBundleA().Output;

            // Install the bundle.
            BundleInstaller installerA = new BundleInstaller(this, bundleA).Install();
            Assert.True(MsiVerifier.IsPackageInstalled(packageA));

            // Copy the package using the bundle package name.
            ProductInstallation product = new ProductInstallation(packageA_ProductCode, null, UserContexts.Machine);
            string packageA_Copy = Path.Combine(packageA_Directory, product.AdvertisedPackageName);
            File.Copy(packageA, packageA_Copy);
            this.TestArtifacts.Add(new FileInfo(packageA_Copy));

            // Repair and recache the MSI.
            MSIExec.InstallProduct(packageA_Copy, MSIExec.MSIExecReturnCode.SUCCESS, "REINSTALL=ALL REINSTALLMODE=vomus");
            Assert.True(MsiVerifier.IsPackageInstalled(packageA));

            // Check that the source contains both the original and burn cached paths.
            SourceList sources = product.SourceList;
            Assert.Equal(2, sources.Count);

            // Attempt to uninstall bundleA.
            installerA.Uninstall();
            Assert.False(MsiVerifier.IsPackageInstalled(packageA));

            this.Completed();
        }
Exemplo n.º 8
0
        public static string GetProductInfo(string productode, MsiProductSearchType type)
        {
            string productInfo = string.Empty;

            ProductInstallation product = new ProductInstallation(productode, "s-1-1-0", UserContexts.All);

            switch(type)
            {
                case MsiProductSearchType.assignment:
                    productInfo = product.Context.ToString(); //TODO
                    break;
                case MsiProductSearchType.language:
                    productInfo = product["ProductLanguage"].ToString();
                    break;
                case MsiProductSearchType.state:
                    productInfo = product.Context.ToString();
                    break;
                case MsiProductSearchType.version:
                    productInfo = product.ProductVersion.ToString();
                    break;
            }

            return productInfo;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Detects the state of the feature.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        static InstallState DetectFeatureState(Session session, string name)
        {
            var productCode = session["ProductCode"];

            var installedPackage = new Microsoft.Deployment.WindowsInstaller.ProductInstallation(productCode);
            if (installedPackage.IsInstalled)
                return installedPackage.Features
                .First(x => x.FeatureName == name)
                .State;
            else
                return InstallState.Absent;
        }
Exemplo n.º 10
0
        // This test does not pass if run normally.
        // It only passes when a failure is injected into the EmbeddedUI launcher.
        ////[TestMethod]
        public void EmbeddedUIInitializeFails()
        {
            string dbFile = "EmbeddedUIInitializeFails.msi";
            string productCode;

            string uiDir = Path.GetFullPath(EmbeddedExternalUI.EmbeddedUISampleBinDir);
            string uiFile = "Microsoft.Deployment.Samples.EmbeddedUI.dll";

            // A number that will be used to check whether a type 19 CA runs.
            const string magicNumber = "3.14159265358979323846264338327950";

            using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect))
            {
                WindowsInstallerUtils.InitializeProductDatabase(db);
                WindowsInstallerUtils.CreateTestProduct(db);

                const string failureActionName = "EmbeddedUIInitializeFails";
                db.Execute("INSERT INTO `CustomAction` (`Action`, `Type`, `Source`, `Target`) " +
                    "VALUES ('{0}', 19, '', 'Logging magic number: {1}')", failureActionName, magicNumber);

                // This type 19 CA (launch condition) is given a condition of 'UILevel = 3' so that it only runs if the
                // installation is running in BASIC UI mode, which is what we expect if the EmbeddedUI fails to initialize.
                db.Execute("INSERT INTO `InstallExecuteSequence` (`Action`, `Condition`, `Sequence`) " +
                    "VALUES ('{0}', 'UILevel = 3', 1)", failureActionName);

                productCode = db.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0];

                using (Record uiRec = new Record(5))
                {
                    uiRec[1] = "TestEmbeddedUI";
                    uiRec[2] = Path.GetFileNameWithoutExtension(uiFile) + ".Wrapper.dll";
                    uiRec[3] = 1;
                    uiRec[4] = (int)(
                        EmbeddedExternalUI.TestLogModes |
                        InstallLogModes.Progress |
                        InstallLogModes.Initialize |
                        InstallLogModes.Terminate |
                        InstallLogModes.ShowDialog);
                    uiRec.SetStream(5, Path.Combine(uiDir, uiFile));
                    db.Execute(db.Tables["MsiEmbeddedUI"].SqlInsertString, uiRec);
                }

                db.Commit();
            }

            Installer.SetInternalUI(InstallUIOptions.Full);

            ProductInstallation installation = new ProductInstallation(productCode);
            Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed before starting.");

            string logFile = "install.log";
            Exception caughtEx = null;
            try
            {
                Installer.EnableLog(EmbeddedExternalUI.TestLogModes, logFile);
                Installer.InstallProduct(dbFile, String.Empty);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(InstallerException),
                "Excpected InstallerException installing product; caught: " + caughtEx);

            Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed.");

            string logText = File.ReadAllText(logFile);
            Assert.IsTrue(logText.Contains(magicNumber), "Checking that the type 19 custom action ran.");
        }
Exemplo n.º 11
0
        public void EmbeddedUISingleInstall()
        {
            string dbFile = "EmbeddedUISingleInstall.msi";
            string productCode;

            string uiDir = Path.GetFullPath(EmbeddedExternalUI.EmbeddedUISampleBinDir);
            string uiFile = "Microsoft.Deployment.Samples.EmbeddedUI.dll";

            using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect))
            {
                WindowsInstallerUtils.InitializeProductDatabase(db);
                WindowsInstallerUtils.CreateTestProduct(db);

                productCode = db.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0];

                using (Record uiRec = new Record(5))
                {
                    uiRec[1] = "TestEmbeddedUI";
                    uiRec[2] = Path.GetFileNameWithoutExtension(uiFile) + ".Wrapper.dll";
                    uiRec[3] = 1;
                    uiRec[4] = (int) (
                        EmbeddedExternalUI.TestLogModes |
                        InstallLogModes.Progress |
                        InstallLogModes.Initialize |
                        InstallLogModes.Terminate |
                        InstallLogModes.ShowDialog);
                    uiRec.SetStream(5, Path.Combine(uiDir, uiFile));
                    db.Execute(db.Tables["MsiEmbeddedUI"].SqlInsertString, uiRec);
                }

                db.Commit();
            }

            Installer.SetInternalUI(InstallUIOptions.Full);

            ProductInstallation installation = new ProductInstallation(productCode);
            Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed before starting.");

            Exception caughtEx = null;
            try
            {
                Installer.EnableLog(EmbeddedExternalUI.TestLogModes, "install.log");
                Installer.InstallProduct(dbFile, String.Empty);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Exception thrown while installing product: " + caughtEx);

            Assert.IsTrue(installation.IsInstalled, "Checking that product is installed.");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("===================================================================");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            try
            {
                Installer.EnableLog(EmbeddedExternalUI.TestLogModes, "uninstall.log");
                Installer.InstallProduct(dbFile, "REMOVE=All");
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Exception thrown while uninstalling product: " + caughtEx);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the weight of a package given its ProductCode.
        /// </summary>
        /// <param name="productCode">The ProductCode of the product to query.</param>
        /// <param name="userSid">The optional user SID of the product to query. The default is null.</param>
        /// <param name="context">The optional context of the product ot query. The default is <see cref="UserContexts.All"/>.</param>
        /// <returns>The weight of a package given its ProductCode or 0 if the product is not installed or the package missing.</returns>
        internal static long GetWeightFromProductCode(string productCode, string userSid = null, UserContexts context = UserContexts.All)
        {
            var product = new ProductInstallation(productCode, userSid, context);
            if (null != product && product.IsInstalled)
            {
                var path = product.LocalPackage;
                if (!string.IsNullOrEmpty(path))
                {
                    return PackageInfo.GetWeightFromPath(path);
                }
            }

            return 0;
        }
Exemplo n.º 13
0
 /// <summary>
 /// Adds properties to the <see cref="ProductInstallation"/> object and writes it to the pipeline.
 /// </summary>
 /// <param name="product">The <see cref="ProductInstallation"/> to write to the pipeline.</param>
 private void WriteProduct(ProductInstallation product)
 {
     var obj = product.ToPSObject(this.SessionState.Path);
     this.WriteObject(obj);
 }
Exemplo n.º 14
0
        private Session OpenProduct(ProductInstallation product)
        {
            // Open the product taking machine state into account.
            var path = product.LocalPackage;
            if (!string.IsNullOrEmpty(path))
            {
                return Installer.OpenPackage(path, this.IgnoreMachineState);
            }
            else if (product.IsAdvertised && !String.IsNullOrEmpty(product.AdvertisedPackageName))
            {
                // Product is advertised and has no locally installed package.
                var message = string.Format(Properties.Resources.Error_Advertised, product.ProductCode);
                this.WriteWarning(message);
            }
            else
            {
                // Product registration is corrupt.
                var message = string.Format(Properties.Resources.Error_Corrupt, product.ProductCode);
                var ex = new Exception(message, new Win32Exception(NativeMethods.ERROR_BAD_CONFIGURATION));
                var error = new ErrorRecord(ex, "Error_Corrupt", ErrorCategory.NotInstalled, product);

                this.WriteError(error);
            }

            return null;
        }