Example #1
0
        private void Run()
        {
            installer        = (WindowsInstaller.Installer) new Installer();
            moSearcher       = new ManagementObjectSearcher();
            moSearcher.Scope = new ManagementScope(@"\\.\ROOT\cimv2");

            if (options.Count == 0)
            {
                for (int i = 0; i < installer.Products.Count; i++)
                {
                    OutputLine(i + 1, installer.Products[i]);
                }
            }
            else
            {
                foreach (var option in options)
                {
                    switch (option)
                    {
                    case "u":
                        var    upgradeCode = GetRelatedUpgradeCode(targetProductCode);
                        string s           = string.Format("UpgradeCode: {0}", upgradeCode);
                        Console.WriteLine(s);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
    public static IEnumerable <MSIInfo> GetProducts()
    {
        Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");

        Installer installerObj = (Installer)Activator.CreateInstance(installerType);

        WindowsInstaller.Installer installer = installerObj as WindowsInstaller.Installer;
        var Products = installerObj.Products;

        List <MSIInfo> ProductCollection = new List <MSIInfo>();

        foreach (var product in Products)
        {
            MSIInfo msi = new MSIInfo();
            msi.ProductCode = product.ToString();

            foreach (var property in msi.GetType()?.GetProperties())
            {
                try
                {
                    if (property.Name != "ProductCode")
                    {
                        string val = installer.ProductInfo[product.ToString(), property.Name];
                        property.SetValue(msi, val);
                    }
                }
                catch (System.Runtime.InteropServices.COMException)
                {
                }
            }
            ProductCollection.Add(msi);
        }

        return(ProductCollection);
    }
Example #3
0
        public static string Get(string msi, string name)
        {
            String inputFile = @"C:\\Rohan\\sqlncli.msi";
            // Get the type of the Windows Installer object
            Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");

            // Create the Windows Installer object
            WindowsInstaller.Installer installer = (WindowsInstaller.Installer)Activator.CreateInstance(installerType);

            // Open the MSI database in the input file
            Database database = installer.OpenDatabase(inputFile, 0);

            // Open a view on the Property table for the version property
            View view = database.OpenView("SELECT * FROM _Tables");

            //View view = database.OpenView("SELECT * FROM Property");

            // Execute the view query
            view.Execute(null);

            // Get the record from the view
            Record record = view.Fetch();

            // Get the version from the data
            //string version = record.get_StringData(2);

            while (record != null)
            {
                Console.WriteLine(record.get_StringData(0) + '=' + record.get_StringData(1) + '=' + record.get_StringData(2) + '=' + record.get_StringData(3));
                record = view.Fetch();
            }
        }
Example #4
0
            static void Main(string[] args)
            {
                //Refactor this later to be cleaner.

                Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");

                WindowsInstaller.Installer installer = (WindowsInstaller.Installer)

                                                       Activator.CreateInstance(type);

                WindowsInstaller.Database db;

                try
                {
                    db = installer.OpenDatabase("..\\..\\..\\..\\TestFile\\IPFilter.msi", 0);
                }
                catch (Exception e)
                {
                    throw new Exception("File does not exist or is not accessible", e);
                }

                Console.WriteLine("[Property]");
                WindowsInstaller.View dv = db.OpenView("SELECT `Property`, `Value` FROM `Property`");

                dv.Execute();

                for (WindowsInstaller.Record row; (row = dv.Fetch()) != null;)
                {
                    Console.WriteLine(row.get_StringData(1).ToString() + "=" + row.get_StringData(2).ToString());
                }
            }
Example #5
0
        private string returnMsiInfo(string SQL)
        {
            Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");

            WindowsInstaller.Installer Installer = (WindowsInstaller.Installer)Activator.CreateInstance(type);
            Activator.CreateInstance(type);

            WindowsInstaller.Database db     = Installer.OpenDatabase(@"\\iomega-nas\Public1\IT Department\Pinnacle\Deploy\PinnacleSetup.msi", 0);
            WindowsInstaller.View     dv     = db.OpenView(SQL);
            WindowsInstaller.Record   record = null;
            dv.Execute(record);

            record = dv.Fetch();

            return(record.get_StringData(1).ToString());
        }
Example #6
0
        private void btnMSI_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtMSILocation.Text))
            {
                if (File.Exists(txtMSILocation.Text))
                {
                    Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
                    WindowsInstaller.Installer installer = Activator.CreateInstance(installerType) as WindowsInstaller.Installer;

                    ////read out the contents of the msi based on the msi location (txtMSILocation.Text)
                    WindowsInstaller.Database db = installer.OpenDatabase(txtMSILocation.Text, 0);

                    ////select properties from the MSI and set text boxes with those values
                    string query = "SELECT Value FROM Property WHERE Property='ProductName'";
                    WindowsInstaller.View view = db.OpenView(query);
                    view.Execute(null);
                    this.txtAppName.Text = view.Fetch().StringData[1];
                    query = "SELECT Value FROM Property WHERE Property='ProductVersion'";
                    view  = db.OpenView(query);
                    view.Execute(null);
                    this.txtSoftwareVersion.Text = view.Fetch().StringData[1];
                    query = "SELECT Value FROM Property WHERE Property='Manufacturer'";
                    view  = db.OpenView(query);
                    view.Execute(null);
                    this.txtManufacturer.Text = view.Fetch().StringData[1];
                    query = "SELECT Value FROM Property WHERE Property='ProductCode'";
                    view  = db.OpenView(query);
                    view.Execute(null);
                    this.txtProductCode.Text = view.Fetch().StringData[1];
                    installer = null;

                    ////dynamically build the install command based on the MSI properties
                    FileInfo file = new FileInfo(txtMSILocation.Text);
                    this.txtInstallCommandLine.Text   = string.Format("MSI Install - msiexec /i {0} /q", file.Name);
                    this.txtUninstallCommandLine.Text = "MSI Uninstall - msiexec /x " + this.txtProductCode.Text + " /q";
                }
                else
                {
                    MessageBox.Show("File not found");
                }
            }
            else
            {
                MessageBox.Show("Please specify MSI location");
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            try
            {
                string strMSIPackage = args[1];

                Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");

                WindowsInstaller.Installer installer = (WindowsInstaller.Installer)Activator.CreateInstance(type);
                WindowsInstaller.Database  db        = installer.OpenDatabase(@strMSIPackage, 0);
                WindowsInstaller.View      dv        = null;

                string strNumber = string.Empty;

                if ((args[0].CompareTo("/v")) == 0)
                {
                    dv        = db.OpenView("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductVersion'");
                    strNumber = GetInstallerString(dv);
                    Console.Write(string.Format("\n{0}", strNumber));
                }
                else if ((args[0].CompareTo("/n")) == 0)
                {
                    dv        = db.OpenView("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductName'");
                    strNumber = GetInstallerString(dv);
                    Match match = Regex.Match(strNumber, @"\d+(?=\.\w)(.*)", RegexOptions.IgnoreCase);

                    if (match.Success)
                    {
                        Console.Write(string.Format("\n{0}", (strNumber.Substring(0, strNumber.Length - match.Value.Length)).Trim( )));
                    }
                }
                else if ((args[0].CompareTo("/a")) == 0)
                {
                    dv = db.OpenView("SELECT `Property`, `Value` FROM `Property`");
                    ShowAllProperties(dv);
                }

                // Environment.SetEnvironmentVariable ( "MSIVERSION", strNumber, EnvironmentVariableTarget.User );
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #8
0
        private static void validateInstallerDetails(string msi, out string installRoot, out string prodName)
        {
            Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");

            WindowsInstaller.Installer installer = (WindowsInstaller.Installer)Activator.CreateInstance(type);
            WindowsInstaller.Database  db        = installer.OpenDatabase(msi, 0);

            WindowsInstaller.View dv_pp = db.OpenView("SELECT `Value` FROM `Property` WHERE `Property`='MYAPPPATH'");
            WindowsInstaller.View dv_pn = db.OpenView("SELECT `Value` FROM `Property` WHERE `Property`='ProductName'");

            WindowsInstaller.Record record_pp = null;
            WindowsInstaller.Record record_pn = null;
            dv_pp.Execute(record_pp);
            record_pp = dv_pp.Fetch(); //product path  Eg : E:\Web
            dv_pn.Execute(record_pn);
            record_pn = dv_pn.Fetch(); //product name

            installRoot = record_pp.get_StringData(1).ToString();
            prodName    = record_pn.get_StringData(1).ToString();

            Console.WriteLine();
            if (string.IsNullOrEmpty(installRoot))
            {
                Console.ForegroundColor = Bad;
                Console.WriteLine("ERROR : The property 'MYAPPPATH' has not been set.  The install path could not be resolved.");
                Console.ForegroundColor = OriginalForeground;
                Environment.Exit(0);
            }

            if (string.IsNullOrEmpty(prodName))
            {
                Console.ForegroundColor = Bad;
                Console.WriteLine("ERROR : The property 'ProductName' has not been set.  The install path could not be resolved.");
                Console.ForegroundColor = OriginalForeground;
                Environment.Exit(0);
            }

            Console.ForegroundColor = Info;
            System.Console.WriteLine("MSI Install path: " + Path.Combine(installRoot, prodName));
            Console.WriteLine();
            Console.ForegroundColor = OriginalForeground;

            validateDirectory(installRoot, true, false);
        }
Example #9
0
        /// <summary>
        /// Gets the MSI file version that is to be installed from the msi, before installing it.
        /// source: https://www.codeproject.com/Articles/31021/Getting-version-from-MSI-without-installing-it
        /// </summary>
        /// <param name="msi"></param>
        /// <returns></returns>
        public static string GetMsiVersion(string msi)
        {
            Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");

            WindowsInstaller.Installer installer = (WindowsInstaller.Installer)

                                                   Activator.CreateInstance(type);

            WindowsInstaller.Database db = installer.OpenDatabase(msi, 0);

            WindowsInstaller.View dv = db.OpenView(
                "SELECT `Value` FROM `Property` WHERE `Property`='ProductVersion'");

            WindowsInstaller.Record record = null;

            dv.Execute(record);

            record = dv.Fetch();

            return(record.get_StringData(1).ToString());
        }
Example #10
0
        static void Main(string[] args)
        {
            bool ChangesMade = false;

            Console.WriteLine("Update an MSI File with a 64bit version of InstallUtilLib");
            Console.WriteLine();

            string InstallUtil64BitFileSpec = ConfigurationManager.AppSettings["InstallUtil64BitFileSpec"];
            string MSIFileSpec = ConfigurationManager.AppSettings["MSIFileSpec"];

            if (System.IO.File.Exists(InstallUtil64BitFileSpec) == false)
            {
                Console.WriteLine("File Not Found : " + InstallUtil64BitFileSpec);
                return;
            }
            if (System.IO.File.Exists(MSIFileSpec) == false)
            {
                Console.WriteLine("File Not Found : " + MSIFileSpec);
                return;
            }

            Console.WriteLine("MSIFile:" + Environment.NewLine + MSIFileSpec);
            Console.WriteLine();
            Console.WriteLine("InstallUtil: " + Environment.NewLine + InstallUtil64BitFileSpec);
            Console.WriteLine();
            Console.WriteLine("Opening the MSI File");
            //WindowsInstaller.Installer i = (WindowsInstaller.Installer)new Fix64BitMSIFile.Installer();

            Type   classType            = Type.GetTypeFromProgID("WindowsInstaller.Installer");
            Object installerClassObject = Activator.CreateInstance(classType);

            WindowsInstaller.Installer i = (WindowsInstaller.Installer)installerClassObject;

            WindowsInstaller.Database db = i.OpenDatabase(MSIFileSpec, WindowsInstaller.MsiOpenDatabaseMode.msiOpenDatabaseModeTransact);
            Console.WriteLine("Running SQL Query for InstallUtil in the Binary MSI table");

            // NOTE: The ` is correct in the SQL statement below - it is not " or '

            WindowsInstaller.View v = db.OpenView("SELECT `Name`,`Data` FROM `Binary` where `Binary`.`Name` = 'InstallUtil'");
            v.Execute(null);
            WindowsInstaller.Record Record = v.Fetch();
            if (Record != null)
            {
                Console.WriteLine("Updating the Binary Data for InstallUtil");
                Record.SetStream(2, InstallUtil64BitFileSpec);
                v.Modify(WindowsInstaller.MsiViewModify.msiViewModifyUpdate, Record);
                ChangesMade = true;
            }
            else
            {
                Console.WriteLine("Error : InstallUtil not found in the Binary MSI Table");
            }
            v.Close();
            if (ChangesMade)
            {
                Console.WriteLine("Commiting the changes to the database");
                db.Commit();
            }

            Console.WriteLine();
            Console.WriteLine("Completed.....");
            Console.ReadLine();
        }