Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
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();
        }