Exemplo n.º 1
0
        /// <summary>
        /// Generates an advertise script. The method enables the installer to write to a
        /// script the registry and shortcut information used to assign or publish a product.
        /// </summary>
        /// <param name="packagePath">Path to the package of the product being advertised</param>
        /// <param name="scriptFilePath">path to script file to be created with the advertise information</param>
        /// <param name="transforms">Semi-colon delimited list of transforms to be applied. This parameter may be null.</param>
        /// <param name="locale">The language to use if the source supports multiple languages</param>
        /// <param name="processor">Targeted processor architecture.</param>
        /// <param name="instance">True to install multiple instances through product code changing transform.
        /// Advertises a new instance of the product. Requires that the <paramref name="transforms"/> parameter
        /// includes the instance transform that changes the product code.</param>
        /// <seealso cref="AdvertiseProduct"/>
        /// <remarks><p>
        /// Win32 MSI APIs:
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msiadvertiseproduct.asp">MsiAdvertiseProduct</a>,
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msiadvertiseproductex.asp">MsiAdvertiseProductEx</a>
        /// </p></remarks>
        public static void GenerateAdvertiseScript(
            string packagePath,
            string scriptFilePath,
            string transforms,
            int locale,
            ProcessorArchitecture processor,
            bool instance)
        {
            if (String.IsNullOrEmpty(packagePath))
            {
                throw new ArgumentNullException("packagePath");
            }

            if (String.IsNullOrEmpty(scriptFilePath))
            {
                throw new ArgumentNullException("scriptFilePath");
            }

            if (!File.Exists(packagePath))
            {
                throw new FileNotFoundException(null, packagePath);
            }

            uint platform = 0;

            switch (processor)
            {
            case ProcessorArchitecture.X86: platform = (uint)1; break;

            case ProcessorArchitecture.IA64: platform = (uint)2; break;

            case ProcessorArchitecture.Amd64: platform = (uint)4; break;
            }

            uint ret = NativeMethods.MsiAdvertiseProductEx(
                packagePath,
                scriptFilePath,
                transforms,
                (ushort)locale,
                platform,
                instance ? (uint)1 : 0);

            if (ret != 0)
            {
                throw InstallerException.ExceptionFromReturnCode(ret);
            }
        }