We have a requirement to allow multiple instances of our program. I followed one of the samples and got everything working when instances are invoked from command line. To provide our users with a better experience we want to add a dialog to our project to allow the user to either modify/remove a selected instance or to install a new instance.
So far new instances and updates work perfectly but I’m struggling with the modify. In a previous wix project I got this working by scheduling the dialog before appsearch. But as we are using a managed project the dialogs are embedded and I’m not sure how to schedule a dialog before Appsearch with this approach. So for now I added the dialog in both the modify and the install dialogs, but I need a way to tell the project to use the modify dialogs if the user chooses not to install a new instance.
I also tried launching the dialog in the UIInitialized event, but think If I want to go this route I need to have a different type of UI (not managed).
Can you please advise what the best way is to set instances after launching?
I’ve attached snippets of code, maybe there is something small we are missing.
So far new instances and updates work perfectly but I’m struggling with the modify. In a previous wix project I got this working by scheduling the dialog before appsearch. But as we are using a managed project the dialogs are embedded and I’m not sure how to schedule a dialog before Appsearch with this approach. So for now I added the dialog in both the modify and the install dialogs, but I need a way to tell the project to use the modify dialogs if the user chooses not to install a new instance.
I also tried launching the dialog in the UIInitialized event, but think If I want to go this route I need to have a different type of UI (not managed).
Can you please advise what the best way is to set instances after launching?
I’ve attached snippets of code, maybe there is something small we are missing.
//managed UI dialogs and sequence
//InstanceSelect is the dialog where the user will choose either a newinstall or a modify
project.ManagedUI = new ManagedUI();
project.ManagedUI.InstallDialogs.Add<WelcomeDialog>()
.Add<InstanceSelect>()
.Add<LicenceDialog>()
.Add<SetupTypeDialog>()
.Add<FeaturesDialog>()
.Add<InstallDirDialog>()
//.Add<ConfigurationDialog>()
.Add<ProgressDialog>()
.Add<ExitDialog>();
project.ManagedUI.ModifyDialogs.Add<WelcomeDialog>()
.Add<InstanceSelect>()
.Add<MaintenanceTypeDialog>()
.Add<FeaturesDialog>()
.Add<ProgressDialog>()
.Add<ExitDialog>();
project.AlwaysScheduleInitRuntime = false;
//setup instance transforms for 5 instances
Compiler.WixSourceGenerated += document =>
{
var instanceTransforms = new XElement("InstanceTransforms", new XAttribute("Property", "INSTANCEID"));
var guids = new string[] {"B2086842-992F-49AE-AB4A-837C2A21B627", "B3086842-992F-49AE-AB4A-837C2A21B627",
"B4086842-992F-49AE-AB4A-837C2A21B627", "B5086842-992F-49AE-AB4A-837C2A21B627",
"B6086842-992F-49AE-AB4A-837C2A21B627"};
var upguids = new string[] {"B2086842-992F-49AE-AB4A-837C2A21B627", "C3086842-992F-49AE-AB4A-837C2A21B627",
"D4086842-992F-49AE-AB4A-837C2A21B627", "E5086842-992F-49AE-AB4A-837C2A21B627",
"F6086842-992F-49AE-AB4A-837C2A21B627"};
for (var instance = 1; instance <= 5; instance++)
instanceTransforms.Add(
new XElement("Instance",
new XAttribute("Id", "Instance" + instance),
new XAttribute("ProductCode", guids[instance - 1]),
new XAttribute("ProductName", "Our product " + instance),
new XAttribute("UpgradeCode", upguids[instance - 1])));
document.Root.Select("Product").Add(instanceTransforms);
};
//upgrades
project.MajorUpgrade = new MajorUpgrade
{
AllowSameVersionUpgrades = true, //uncomment this if the the upgrade version is different by only the fourth field
Schedule = UpgradeSchedule.afterInstallInitialize,
DowngradeErrorMessage = "A later version of [ProductName] is already installed. Setup will now exit."
};
InstanceSelect dialog snippets:void dialog_Load(object sender, EventArgs e)
{
banner.Image = MsiRuntime.Session.GetEmbeddedBitmap("WixUI_Bmp_Banner");
Text = "[ProductName] Setup";
//resolve all Control.Text cases with embedded MSI properties (e.g. 'ProductName') and *.wxl file entries
base.Localize();
//load installed instances to select from
instances = new List<RegistryInstance>();
RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"software\compname\instance");
if (rk == null)
rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\compname\instance");
//look for registry entry and set next available instance
if (rk != null)
{
for(int i = 1; i<=5; i++)
{
if (rk.GetValue("Instance" + i) != null && rk.GetValue("Instance" + i).ToString() != "0")
{
instances.Add(new RegistryInstance("Instance" + i, rk.GetValue("Instance" + i).ToString()));
checkedListBox1.Items.Add(instances[i - 1].sDirectory);
}
}
}
//if (instances.Count <= 0)
// btnNew.PerformClick();
}
void cancel_Click(object sender, EventArgs e)
{
Shell.Cancel();
}
private void btnNew_Click(object sender, EventArgs e)
{
int nInstance = 1;
if (instances.Count > 0)
nInstance = instances.Count + 1;
MsiRuntime.Session["INSTANCEID"] = "Instance"+ nInstance;
MsiRuntime.Session["TRANSFORMS"] = ":" + MsiRuntime.Session["INSTANCEID"] + ";";
//set default install directory with name of instance id
MsiRuntime.Session["INSTALLDIR"] = @"C:\Me " + MsiRuntime.Session["INSTANCEID"];
MsiRuntime.Session["MSINEWINSTANCE"] = "1";
Shell.GoNext();
}
private void btnModify_Click(object sender, EventArgs e)
{
int nInstance = 1;
if (checkedListBox1.SelectedIndices.Count > 0)
{
nInstance = checkedListBox1.SelectedIndices[0] + 1;
MessageBox.Show("checked instance" + nInstance);
MsiRuntime.Session["INSTANCEID"] = "Instance" + nInstance;
MsiRuntime.Session["TRANSFORMS"] = ":" + MsiRuntime.Session["INSTANCEID"] + ";";
//set default install directory with name of instance id
MsiRuntime.Session["INSTALLDIR"] = @"C:\Me " + MsiRuntime.Session["INSTANCEID"];
MsiRuntime.Session["MSINEWINSTANCE"] = "1";
//added the following section to try and force the maintenace sequence but
//when trying to remove installed product I get:
//DEBUG: Error 2755: Server returned unexpected error 1639 attempting to install package
Shell.Dialogs.Clear();
Shell.Dialogs.Add<WelcomeDialog>();
Shell.Dialogs.Add<InstanceSelect>();
Shell.Dialogs.Add<MaintenanceTypeDialog>();
Shell.Dialogs.Add<FeaturesDialog>();
Shell.Dialogs.Add<ProgressDialog>();
Shell.Dialogs.Add<ExitDialog>();
Shell.GoNext();
}
}
}