コード例 #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
        private string getCustomActionPathSet(String varName) //TODO: resolve the condition field as custom action might not be used
        {
            String resPath = null;

            WindowsInstaller.View view = null;

            try
            {
                view = database.OpenView("SELECT * FROM `CustomAction` where Source='" + varName + "'");
                view.Execute();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to query msi, " + ex.Message);
            }


            Record properties = view.Fetch();

            while (properties != null)
            {
                int setPropActio = properties.get_IntegerData(2) & 51;

                if (setPropActio == 51)
                {
                    resPath = properties.get_StringData(4);
                }
                properties = view.Fetch();
            }
            Console.WriteLine("51 " + varName + "--" + resPath);
            return(resPath);
        }
コード例 #3
0
        /// <summary>
        /// Get an MSI Property
        /// </summary>
        /// <param name="sProperty">MSI Property Name</param>
        /// <returns>Value of an MSI Property</returns>
        public string Property(string sProperty)
        {
            try
            {
                WindowsInstaller.View vMSI = msiDatabase.OpenView("SELECT * FROM Property");
                vMSI.Execute(null);
                Record iRec = vMSI.Fetch();
                while (iRec != null)
                {
                    if (string.Compare(iRec.get_StringData(1), sProperty, true) == 0)
                    {
                        return(iRec.get_StringData(2));
                    }

                    iRec = vMSI.Fetch();
                }

                return("");
            }
            catch (Exception ex)
            {
                return("");
            }
            finally
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
コード例 #4
0
        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();
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: alexfreu69/MSIChecker
        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);
        }
コード例 #6
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);
        }
コード例 #7
0
ファイル: MSIQuery.cs プロジェクト: CKL44/DMA_NEXT
        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);
        }
コード例 #8
0
        //获取MSI文件的版本号
        private static String getMsiFileVersion(String msiPath)
        {
            System.Type oType = System.Type.GetTypeFromProgID("WindowsInstaller.Installer");
            Installer   inst  = System.Activator.CreateInstance(oType) as Installer;
            Database    DB    = inst.OpenDatabase(msiPath, MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);
            string      str   = "SELECT * FROM Property WHERE Property = 'ProductVersion'"; //读取文件版本号

            string ProductVersion = "";

            if (str != "")
            {
                WindowsInstaller.View thisView = DB.OpenView(str);
                thisView.Execute();
                WindowsInstaller.Record thisRecord = thisView.Fetch();
                ProductVersion = thisRecord.get_StringData(2);       //获取特定的数据列
            }

            Console.WriteLine("文件版本号:" + ProductVersion);

            //获取失败
            //FileVersionInfo fvi = FileVersionInfo.GetVersionInfo("E:\\Users\\MVP\\Desktop\\ApplicationLibrary\\MSI\\腾讯QQ.msi");
            //Console.WriteLine("文件版本号:" + fvi.FileVersion);

            return(ProductVersion);
        }
コード例 #9
0
ファイル: MSIQuery.cs プロジェクト: CKL44/DMA_NEXT
        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);
        }
コード例 #10
0
        private void parseShortcuts()
        {
            WindowsInstaller.View view = queryMsi("SELECT * FROM `Shortcut`");

            Record record = view.Fetch();
            List <MsiShortCuts> shortCuts = new List <MsiShortCuts>();

            while (record != null)
            {
                MsiShortCuts msiShortcut = new MsiShortCuts();
                msiShortcut.ShortCut           = record.get_StringData(1);
                msiShortcut.StartMenuDirectory = resolveMsiVar(record.get_StringData(2));
                msiShortcut.Name      = cleanShortCutName(record.get_StringData(3));
                msiShortcut.Component = record.get_StringData(4);

                if (isAdvertised(record.get_StringData(5)))
                {
                    Console.WriteLine("ishAdvertised...");
                    MsiComponent msiComponent = getComponent(record.get_StringData(4));

                    if (msiComponent != null)
                    {
                        msiShortcut.ShortCutTarget = getTargetPath(msiComponent.Directory) + getFile(msiComponent.KeyPath).FileName;
                        Console.WriteLine("ishAdvertised with keypath..." + msiComponent.KeyPath + "::" + getTargetPath(msiComponent.Directory) + getFile(msiComponent.KeyPath).FileName);
                    }
                    else
                    {
                        Environment.ExitCode = 2;
                    }
                }
                else
                {
                    msiShortcut.ShortCutTarget = resolveMsiVar(record.get_StringData(5));
                }


                msiShortcut.workingDir = resolveMsiVar(record.get_StringData(12));
                shortCuts.Add(msiShortcut);
                record = view.Fetch();
            }

            msiProperties.Shortcuts = shortCuts;
        }
コード例 #11
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);
        }
コード例 #12
0
        private Record getMsiRecord(string query)
        {
            Installer installer = (Installer)Activator.CreateInstance(
                Type.GetTypeFromProgID("WindowsInstaller.Installer"));

            Database database = installer.OpenDatabase(SetupFilePath, 0);

            WindowsInstaller.View view = database.OpenView(query);
            view.Execute(null);
            return(view.Fetch());
        }
コード例 #13
0
        private bool isAdvertised(string Name)
        {
            WindowsInstaller.View view = queryMsi("SELECT * FROM `Feature` where Feature='" + Name + "'");
            Record record = view.Fetch();

            if (record != null)
            {
                return(true);
            }

            return(false);
        }
コード例 #14
0
ファイル: MSIOps.cs プロジェクト: vsharmanov/easy-deploy
        public MSIOps(String msiP)
        {
            InitializeComponent();

            logDirectory.Text = Settings.LOGGING_DIR + "\\MSI\\";
            installer.Text    = msiP;

            Type      t    = Type.GetTypeFromProgID("WindowsInstaller.Installer");
            Installer inst = (Installer)Activator.CreateInstance(t);
            Database  d    = inst.OpenDatabase(msiP, MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);

            WindowsInstaller.View v = d.OpenView("SELECT * FROM Property WHERE Property = 'ProductName'");
            v.Execute(null);
            Record r = v.Fetch();

            MSIProductName.Text = r.get_StringData(2);

            v = d.OpenView("SELECT * FROM Property WHERE Property = 'ProductVersion'");
            v.Execute(null);
            r = v.Fetch();
            MSIPVersion.Text = r.get_StringData(2);
        }
コード例 #15
0
        private void parseDirectory()
        {
            WindowsInstaller.View view = null;
            try
            {
                view = database.OpenView("SELECT * FROM `Directory`");
                view.Execute();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to query msi, " + ex.Message);
            }
            directoryTable = new Hashtable();

            Record properties = view.Fetch();

            while (properties != null)
            {
                directoryTable.Add(properties.get_StringData(1).ToLower(), new MsiDirectory(properties.get_StringData(1), properties.get_StringData(2), properties.get_StringData(3)));
                properties = view.Fetch();
            }
        }
コード例 #16
0
ファイル: MSIQuery.cs プロジェクト: CKL44/DMA_NEXT
        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);
        }
コード例 #17
0
        private MsiRegistry getRegistry(string Registry)
        {
            WindowsInstaller.View view = queryMsi("SELECT * FROM `Registry` where Registry='" + Registry + "'");

            Record      record      = view.Fetch();
            MsiRegistry msiRegistry = new MsiRegistry();

            if (record != null)
            {
                msiRegistry.Registry  = record.get_StringData(1);
                msiRegistry.Root      = record.get_IntegerData(2);
                msiRegistry.Key       = record.get_StringData(3);
                msiRegistry.Name      = record.get_StringData(4);
                msiRegistry.Value     = record.get_StringData(5);
                msiRegistry.Component = record.get_StringData(6);
            }

            return(msiRegistry);
        }
コード例 #18
0
        private MsiFile getFile(string File)
        {
            WindowsInstaller.View view = queryMsi("SELECT * FROM `File` where File='" + File + "'");

            Record  record  = view.Fetch();
            MsiFile msiFile = new MsiFile();

            if (record != null)
            {
                msiFile.File      = record.get_StringData(1);
                msiFile.Component = record.get_StringData(2);
                msiFile.FileName  = record.get_StringData(3);
                msiFile.FileSize  = record.get_IntegerData(4);
                msiFile.Version   = record.get_StringData(5);
                msiFile.Language  = record.get_StringData(6);
                msiFile.Attribute = record.get_IntegerData(7);
            }

            return(msiFile);
        }
コード例 #19
0
ファイル: Form1.cs プロジェクト: kataya/Msi_Info
        /// <summary>
        /// Msi ファイルからアンインストール時に必要な情報を取得するメソッド
        ///
        /// 参考1: Read Properties from an MSI File
        ///   http://www.alteridem.net/2008/05/20/read-properties-from-an-msi-file/
        ///
        /// 参考2: 1で COM Microsoft Windows Installer Object Library を参照しようとした時のエラー回避方法
        ///   %WINDIR%\system32\msi.dll をかわりに追加するとよい
        ///   http://www.reinholdt.me/2015/07/29/problem-adding-a-c-reference-to-windowsinstaller-com-object/
        ///
        /// 参考3:  Windows SDK Components for Windows Installer Developers に含まれる View Installer Script の解説
        ///   https://docs.microsoft.com/en-us/windows/desktop/Msi/view-installer-script
        ///
        /// </summary>
        /// <param name="msiFile"></param>
        /// <param name="property"></param>
        /// <returns></returns>
        public static string GetMsiProperty(string msiFile, string property)
        {
            string retVal = string.Empty;


            // インストーラのインスタンスを作成
            Type      classType    = Type.GetTypeFromProgID("WindowsInstaller.Installer");
            Object    installerObj = Activator.CreateInstance(classType);
            Installer installer    = installerObj as Installer;

            // 読み込みのために msi ファイルをオープン
            // OpneDatabase method
            // 0 - Read, 1 - Read/Write
            Database database = installer.OpenDatabase(msiFile, 0);

            // SQL文でプロパティをクエリして取得
            // OpneView method
            string sql = String.Format(
                "SELECT Value FROM Property WHERE Property ='{0}'", property);

            WindowsInstaller.View view = database.OpenView(sql);

            // Execute method and Fetch method
            view.Execute(null);
            // 取得したレコードの読み込み
            Record record = view.Fetch();

            // StringData property
            if (record != null)
            {
                // プロパティの値を返す
                //retVal = string.Format("{0}: {1}", property, record.get_StringData(1));

                // アンインストール用のコマンドの形式で返す
                // mxiexec /X <PruductGUID>
                retVal = string.Format("mxiexec /X '{0}'", record.get_StringData(1));
            }
            retVal = retVal.Replace("'", "\"");

            return(retVal);
        }
コード例 #20
0
        private MsiComponent getComponent(string componentName)
        {
            WindowsInstaller.View view = queryMsi("SELECT * FROM `Component` where Component='" + componentName + "'");


            Record       record       = view.Fetch();
            MsiComponent msiComponent = new MsiComponent();

            if (record != null)
            {
                msiComponent.ComponentName = record.get_StringData(1);
                msiComponent.ComponentId   = record.get_StringData(2);
                msiComponent.Directory     = record.get_StringData(3);
                msiComponent.Atribute      = record.get_IntegerData(4);
                msiComponent.Condition     = record.get_StringData(5);
                msiComponent.KeyPath       = record.get_StringData(6);
            }


            return(msiComponent);
        }
コード例 #21
0
        private static string GetMsiVersion(string fullFile)
        {
            Type installerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");

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

            // Open the MSI database in the input file
            Database database = installer.OpenDatabase(fullFile, MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);

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

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

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

            // Get the version from the data
            return(record.get_StringData(2));
        }
コード例 #22
0
        private void parseProperties()
        {
            WindowsInstaller.View view = null;
            try
            {
                view = database.OpenView("SELECT * FROM `Property`");
                view.Execute();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unable to query msi, " + ex.Message);
            }

            msiProperties = new MsiProperties();
            Record properties = view.Fetch();

            while (properties != null)
            {
                switch (properties.get_StringData(1).ToLower())
                {
                case "manufacturer":
                    msiProperties.Manufacturer = properties.get_StringData(2);
                    break;

                case "productname":
                    msiProperties.ProductName = properties.get_StringData(2);
                    break;

                case "arpcomments":
                    msiProperties.ArpComments = properties.get_StringData(2);
                    break;

                case "arphelplink":
                    msiProperties.ArpHelpLink = properties.get_StringData(2);
                    break;

                case "arpcontact":
                    msiProperties.ArpContact = properties.get_StringData(2);
                    break;

                case "allusers":
                    msiProperties.AllUsers = properties.get_StringData(2);
                    break;

                case "arpinstalllocation":
                    msiProperties.ArpInstallLocation = properties.get_StringData(2);
                    break;

                case "arptelephone":
                    msiProperties.ArpTelephone = properties.get_StringData(2);
                    break;

                case "primaryfolder":
                    msiProperties.PrimaryFolder = properties.get_StringData(2);
                    break;

                case "msiinstallperuser":
                    msiProperties.MsiInstallPerUser = properties.get_StringData(2);
                    break;

                case "reboot":
                    msiProperties.Reboot = properties.get_StringData(2);
                    break;

                case "rootdrive":
                    msiProperties.RootDrive = properties.get_StringData(2);
                    break;

                case "targetdir":
                    msiProperties.TargetDir = properties.get_StringData(2);
                    break;

                case "installdir":
                    msiProperties.InstallDir = properties.get_StringData(2);
                    break;

                case "upgradecode":
                    msiProperties.UpgradeCode = properties.get_StringData(2);
                    break;

                case "productcode":
                    msiProperties.ProductCode = properties.get_StringData(2);
                    break;

                case "productversion":
                    msiProperties.ProductVersion = properties.get_StringData(2);
                    break;

                case "productlanguage":
                    msiProperties.ProductLanguage = properties.get_StringData(2);
                    break;
                }

                properties = view.Fetch();
            }
        }
コード例 #23
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);
        }