static string GetInstallerString(WindowsInstaller.View msview) { WindowsInstaller.Record record = null; msview.Execute(record); record = msview.Fetch(); return(record.get_StringData(1).ToString()); }
static void ShowAllProperties(WindowsInstaller.View msview) { WindowsInstaller.Record record = null; msview.Execute(record); record = msview.Fetch(); while (record != null) { Console.Write(string.Format("\n{0}\t{1}", record.get_StringData(1), record.get_StringData(2))); record = msview.Fetch(); } }
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()); }
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); }
/// <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()); }
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(); }