Custom Installer in .Net showing Form behind installer

橙三吉。 提交于 2019-11-28 00:04:13

If you want to show your own UI in the installer, you won't be able to use a setup and deployment project, because it lacks the features necessary to implement that. Consider using an installer toolkit like WiX or Inno Setup instead.

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

although i'm not wuite sure what exactly you're asking for, using WiX for building windows installers is the prefered way to go. There you can build your forms and custom actions and pretty much anything else.

If you want to have complete control over installer user interface for branding or custom dialogs and don't want to use installer builder software like InstallShield then you can create a C++ application to serve as shell for Windows Installer - there is no need to implement installer actions such as copying files by yourself.

Windows Installer has API for such purpose. With function MsiSetExternalUIRecord you can provide a callback to capture installer notifications such as messages and progress updates.

Dialogs created by custom actions are always displayed behind the installation dialogs on newer Windows versions (Vista and Windows 7). This is because Windows prevents applications to move a window on top of all other windows. Think how virus popups would fill up the screen on older Windows versions.

Instead, a newly created dialog is displayed in the background and it's title bar button (if it has one) flashes.

The correct solution for what you want is creating a dialog in your MSI package and using it instead of the custom action.

milo

Top most won't work. Simply make the form to be displayed in the custom action larger than the MSI installer form.

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

And if it still doesn't show up the try putting just MessageBox to see if your installer is hooked or not with setup 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);
    }

You can use form option TopMost and Focus method. But there much better way. You can get installer process, then get it window handler and then use it as parameter in 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 is something like this:

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

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

user6735630

Call this.focus() in your form.OnLoad method. That makes it show up in front of the installer. Simple fix.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!