Custom installer in .Net shows the form behind the installer

[RunInstaller(true)] public partial class Installer1 : Installer { public Installer1() { InitializeComponent(); } public override void Install(System.Collections.IDictionary stateSaver) { base.Install(stateSaver); } private void Installer1_AfterInstall(object sender, InstallEventArgs e) { Form1 topmostForm = new Form1(); topmostForm.BringToFront(); topmostForm.TopMost = true; topmostForm.ShowDialog(); } } 

I need to display topmostForm in front of the default windows installer user interface. The above code example is inside my CustomAction, which I use to create the form. Setting the TopMost property or using ShowDialog does not help. Is there any other solution to make my form the most central and focused?

+7
source share
10 answers

If you want to show your own interface in the installer, you will not be able to use the installation and deployment project, because it lacks the functions necessary for its implementation. Consider using installer tools such as WiX or Inno Setup instead.

As for the first part of your question, are you passing a custom dialog in the owner argument to MessageBox.Show () ?

+3
source

although I'm not sure what exactly you ask, using WiX to create Windows installers is the preferred way to go. There you can create your own forms and user actions and much more.

+2
source

If you want full control over the installer’s user interface for branding or custom dialogs and don’t want to use installer software such as InstallShield, then you can create a C ++ application to act as a shell for the Windows installer - there’s no need to implement installer actions, such as copying files yourself.

Windows Installer has an API for this purpose. Using the MsiSetExternalUIRecord function, you can provide a callback to capture installer notifications, such as messages and run updates.

+2
source

Dialogs created by user actions are always displayed behind the installation dialogs in new versions of Windows (Vista and Windows 7). This is because Windows prevents applications from moving the window on top of all other windows. Think about how pop-ups will fill the screen in older versions of Windows.

Instead, a newly created dialog is displayed in the background, and the title button (if any) flashes.

The right solution for you is to create a dialog in your MSI package and use it instead of a custom action.

+2
source

Top will no longer work. Simply create a form to display in a custom action that is larger than the MSI installation form.

+2
source

I tried the same and I see the form. The only difference I see is that you are missing base.OnAfterInstall (savedState); in your code.

And if it still does not appear, try installing only MessageBox to see if your installer is connected or not with the configuration project

  protected override void OnAfterInstall(IDictionary savedState) { // message box to test MessageBox.Show("test"); Verify topmostForm = new Verify(); topmostForm.BringToFront(); topmostForm.TopMost = true; topmostForm.ShowDialog(); //this line is missing in your code base.OnAfterInstall(savedState); } 
+1
source

You can use the TopMost and Focus form options. But there is a much better way. You can get the installation process, then get its window handler, and then use it as a parameter in the ShowDialog :: method

 var proc = Process.GetProcessesByName("msiexec").FirstOrDefault(p => p.MainWindowTitle == "Name of product"); var formResult = proc != null ? form.ShowDialog(new WindowWrapper(proc.MainWindowHandle)) : form.ShowDialog(); 

WindowWrapper looks something like this:

 public class WindowWrapper : IWin32Window { private readonly IntPtr hwnd; public IntPtr Handle { get { return hwnd; } } public WindowWrapper(IntPtr handle) { hwnd = handle; } } 
+1
source

Call Minimize and Restore / show form methods, this will fix your problem.

0
source

Call this.focus() in the form.OnLoad method. This makes it appear in front of the installer. Simple fix.

0
source

All Articles