Exemplo n.º 1
0
        static void Update
            (WindowsInstaller.Database database, string table, string filter, int column, string value)
        {
            var view = database.OpenView($@"Select * FROM {table} WHERE {filter}");

            view.Execute();
            var record = view.Fetch();

            record.StringData[column] = value;
            view.Modify(MsiViewModify.msiViewModifyUpdate, record);
        }
        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();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //"C:\Windows\System32\msi.dll"

            var path = @"Release\SetupProject.msi";

            var msi = new WindowsInstallerClass() as WindowsInstaller.Installer;


            WindowsInstaller.Database database =
                msi.OpenDatabase(path, WindowsInstaller.MsiOpenDatabaseMode.msiOpenDatabaseModeTransact);

            var ExitAppName   = "_2548E01E_23FC_4621_9D97_67C658AC7578";
            var LaunchAppName = "_E7893FAB_E790_4DDD_B0B5_DC7AACC28A69";

            Update(database, "InstallExecuteSequence", $@"Action = '{ExitAppName}'", 3, "789");
            Update(database, "InstallExecuteSequence", $@"Action = '{ExitAppName}'", 2, "");
            Update(database, "CustomAction", $@"Action = '{ExitAppName}'", 2, "1");


            Update(database, "CustomAction", $@"Action = '{LaunchAppName}'", 2, "6");

            Update(database, "ControlEvent", $@"Dialog_ = 'FinishedForm' AND Argument = 'Return'", 6, "1");


            {
                var view = database
                           .OpenView($@"DELETE FROM InstallExecuteSequence WHERE Action = '{LaunchAppName}'");
                view.Execute();
            }


            {
                var sql = $@"INSERT INTO ControlEvent (Dialog_,Control_,Event,Argument,Condition,Ordering)"
                          + $@" VALUES('FinishedForm','CloseButton','DoAction','{LaunchAppName}','1','0')";
                database.OpenView(sql).Execute();
            }

            {
                var sql = $@"INSERT INTO Property (Property,Value) VALUES('DISABLEADVTSHORTCUTS','1')";
                database.OpenView(sql).Execute();
            }

            database.Commit();
        }