示例#1
0
        private void FillColumnsOrder(SortedDictionary <string, Table> tables)
        {
            try
            {
                // Open a view on the Property table for the version property
                string request             = "SELECT * FROM _Columns";
                WindowsInstaller.View view = this._database.OpenView(request);

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

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

                while (record != null)
                {
                    string tableName  = record.StringData[1];
                    int    number     = record.IntegerData[2];
                    string columnName = record.StringData[3];

                    tables[tableName].GetColumn(columnName).Order = number;
                    tables[tableName].IsOrdered = true;
                    record = view.Fetch();
                }
                view.Close();
            }
            catch (Exception) { }
        }
示例#2
0
        public string QueryMSI(string fileLocation, string query)
        {
            string   result  = string.Empty;
            FileInfo msiFile = new FileInfo(fileLocation);

            //Hashtable msiData = new Hashtable();
            WindowsInstaller.Installer inst = (WindowsInstaller.Installer) new Installer();
            try
            {
                Database instDb            = inst.OpenDatabase(msiFile.FullName, WindowsInstaller.MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);
                WindowsInstaller.View view = instDb.OpenView(query);
                view.Execute(null);
                Record record = view.Fetch();



                //string fileName = record.get_StringData(1);



                // record = view.Fetch();


                result = record.get_StringData(1);
                view.Close();
            }

            catch (Exception ex)
            { }

            return(result);
        }
示例#3
0
        /// <summary>
        /// Retrieves the value of a property.
        /// </summary>
        /// <param name="PropertyName">Name of the Property to query.</param>
        /// <returns>Return a string which contain the result of the query. If an error occurs, return an empty string.</returns>
        internal string RetrievePropertyValue(string PropertyName)
        {
            string result = string.Empty;

            WindowsInstaller.View view = null;

            try
            {
                // Open a view on the Property table for the version property
                view = this._database.OpenView($"SELECT * FROM Property WHERE Property='{PropertyName}'");

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

                // Get the record from the view
                Record record = view.Fetch();
                result = record.get_StringData(2);
            }
            catch (Exception) { }
            finally
            {
                view?.Close();
            }

            return(result);
        }
示例#4
0
        private string QueryDB(Database msiDatabase, string strProperty)
        {
            string result = null;

            /*
             * string sql = "SELECT Property, Value FROM Property";
             * WindowsInstaller.View view = msiDatabase.OpenView(sql);
             * view.Execute(null);
             *
             * Record record = view.Fetch();
             * do
             * {
             *  String value = record.get_StringData(1);
             *  if (String.Compare(value, strProperty, StringComparison.OrdinalIgnoreCase) == 0)
             *  {
             *      result = record.get_StringData(2);
             *  }
             *  record = view.Fetch();
             * } while (record != null);
             */
            string sql = "SELECT Value FROM Property WHERE Property = '" + strProperty + "'";

            WindowsInstaller.View view = msiDatabase.OpenView(sql);
            view.Execute(null);
            Record record = view.Fetch();

            if (record != null)
            {
                result = record.get_StringData(1);
            }

            view.Close();
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(view);
            return(result);
        }
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Incorrect args.");
                return;
            }

            //arg 1 - path to MSI
            string PathToMSI = args[0];
            //arg 2 - path to assembly
            string PathToAssembly = args[1];

            Type InstallerType;

            WindowsInstaller.Installer Installer;
            InstallerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
            Installer     = (WindowsInstaller.Installer)Activator.CreateInstance(InstallerType);

            Assembly Assembly           = Assembly.LoadFrom(PathToAssembly);
            string   AssemblyStrongName = Assembly.GetName().FullName;
            string   AssemblyVersion    = Assembly.GetName().Version.ToString();

            string SQL = "SELECT `Key`, `Name`, `Value` FROM `Registry`";

            WindowsInstaller.Database Db   = Installer.OpenDatabase(PathToMSI, WindowsInstaller.MsiOpenDatabaseMode.msiOpenDatabaseModeDirect);
            WindowsInstaller.View     View = Db.OpenView(SQL);
            View.Execute();
            WindowsInstaller.Record Rec = View.Fetch();
            while (Rec != null)
            {
                for (int c = 0; c <= Rec.FieldCount; c++)
                {
                    string Column = Rec.get_StringData(c);
                    Column = Column.Replace("[AssemblyVersion]", AssemblyVersion);
                    Column = Column.Replace("[AssemblyStrongName]", AssemblyStrongName);
                    Rec.set_StringData(c, Column);
                    View.Modify(MsiViewModify.msiViewModifyReplace, Rec);
                    Console.Write("{0}\t", Column);
                    Db.Commit();
                }
                Console.WriteLine();
                Rec = View.Fetch();
            }
            View.Close();

            GC.Collect();
            Marshal.FinalReleaseComObject(Installer);

            Console.ReadLine();
        }
示例#6
0
        private DataTable QueryMSIFileandVersions(string query)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Filename");
            dt.Columns.Add("Version");



            FileInfo msiFile = new FileInfo(_mSIfileLocation);

            //Hashtable msiData = new Hashtable();
            WindowsInstaller.Installer inst = (WindowsInstaller.Installer) new Installer();
            try
            {
                Database instDb            = inst.OpenDatabase(msiFile.FullName, WindowsInstaller.MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);
                WindowsInstaller.View view = instDb.OpenView(query);
                view.Execute(null);
                Record record = view.Fetch();


                while (record != null)
                {
                    DataRow dr = dt.NewRow();
                    dr[0] = record.get_StringData(1);
                    dr[1] = record.get_StringData(2);


                    dt.Rows.Add(dr);



                    record = view.Fetch();
                }

                // close the database


                view.Close();
            }
            catch (Exception ex)
            {
            }

            return(dt);
        }
示例#7
0
        /// <summary>
        /// Query the requested Table from the MSI file and return all properties with their values.
        /// </summary>
        /// <param name="table">Name of the MSI Table to query.</param>
        /// <returns>Return a Dictionnary with property name as key and property value as value.</returns>
        internal Table GetAllMSIValuesFromTable(Table table)
        {
            WindowsInstaller.View view = null;

            try
            {
                string columnsName = String.Empty;
                foreach (Column column in table.Columns)
                {
                    columnsName += $"{column.Name}, ";
                    column.Values.Clear();
                }
                columnsName = columnsName.Substring(0, columnsName.LastIndexOf(","));

                // Open a view on the Property table for the version property
                view = this._database.OpenView($"SELECT {columnsName} FROM {table.Name}");

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

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

                while (record != null)
                {
                    int i = 1;
                    foreach (Column column in table.Columns)
                    {
                        column.Values.Add(record.StringData[i]);
                        i++;
                    }
                    record = view.Fetch();
                }
            }
            catch (Exception) { }
            finally
            {
                view?.Close();
            }

            return(table);
        }
示例#8
0
        private Dictionary <string, string> QueryMSI(string query)
        {
            Dictionary <string, string> FilesAndVersion = new Dictionary <string, string>();
            FileInfo msiFile = new FileInfo(_mSIfileLocation);

            //Hashtable msiData = new Hashtable();
            WindowsInstaller.Installer inst = (WindowsInstaller.Installer) new Installer();
            try
            {
                Database instDb            = inst.OpenDatabase(msiFile.FullName, WindowsInstaller.MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);
                WindowsInstaller.View view = instDb.OpenView(query);
                view.Execute(null);
                Record record = view.Fetch();


                while (record != null)
                {
                    //string fileName = record.get_StringData(1);



                    record = view.Fetch();
                    FilesAndVersion.Add(record.get_StringData(1), record.get_StringData(2));
                }

                // close the database


                view.Close();
            }



            catch (Exception ex)
            {
            }

            return(FilesAndVersion);
        }
示例#9
0
        /// <summary>
        /// Return the list of all Tables in this MSI file.
        /// </summary>
        /// <returns>List of all Table name.</returns>
        internal SortedDictionary <string, Table> GetAllMSITables()
        {
            WindowsInstaller.View view = null;

            try
            {
                // Open a view on the Property table for the version property
                view = this._database.OpenView("SELECT * FROM _Validation");

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

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

                while (record != null)
                {
                    string tableName  = record.StringData[1];
                    string columnName = record.StringData[2];
                    string nullable   = record.StringData[3];
                    int?   minValue   = null;
                    if (!string.IsNullOrEmpty(record.StringData[4]))
                    {
                        minValue = record.IntegerData[4];
                    }
                    int?maxValue = null;
                    if (!string.IsNullOrEmpty(record.StringData[5]))
                    {
                        maxValue = record.IntegerData[5];
                    }
                    string keyTable  = record.StringData[6];
                    short? keyColumn = null;
                    if (!string.IsNullOrEmpty(record.StringData[7]))
                    {
                        keyColumn = (short)record.IntegerData[7];
                    }
                    string category    = record.StringData[8];
                    string set         = record.StringData[9];
                    string description = record.StringData[10];

                    Column column = new Column(columnName, nullable, minValue, maxValue, keyTable, keyColumn, category, set, description);

                    if (_tables.ContainsKey(tableName))
                    {
                        _tables[tableName].Columns.Add(column);
                    }
                    else
                    {
                        Table table = new Table
                        {
                            Name = tableName
                        };
                        table.Columns.Add(column);
                        _tables.Add(tableName, table);
                    }
                    record = view.Fetch();
                }
            }
            catch (Exception) { }
            finally
            {
                view?.Close();
            }

            FillColumnsOrder(_tables);
            return(_tables);
        }