从MSI启动的第三方应用程序显示在后台

时间:2014-09-30 22:05:24

标签: wix windows-installer

我有一个用WiX编写的MSI,它在设置过程中调用第三方应用程序。我可以让应用程序执行,但它会在安装程序后面的后台打开。有没有办法让应用程序出现在安装程序前面?

有问题的应用程序需要提升权限,因此无法从“完成”对话框中运行它。

2 个答案:

答案 0 :(得分:0)

您使用的是EXE命令吗?我相信这个自定义操作扩展程序在前面运行程序。如果没有,你总是可以写自己的。

How To: Run the Installed Application After Setup

答案 1 :(得分:0)

我最近才想到最好的方法。我从多个来源拼凑起来。这是针对C#Custom动作启动exe的。您也可以通过Wix ExeCommand启动exe,并在手动查找正确的进程后使用自定义操作将其转发。

[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport("user32.dll")]
static extern IntPtr GetTopWindow(IntPtr hWnd);

static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2); 

const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_SHOWWINDOW = 0x0040;

[CustomAction]
public static ActionResult BringExeForward(Session session)
{

    ProcessStartInfo processInfo = new ProcessStartInfo("Application.exe");
    Process bProcess = Process.Start(processInfo);

    while (GetTopWindow((IntPtr)null) != bProcess.MainWindowHandle)
    {
        SetWindowPos(bProcess.MainWindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
    }

    SetWindowPos(bProcess.MainWindowHandle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);

    return ActionResult.Success;

}
相关问题