2014-09-30 128 views
1

我有一个使用WiX编写的MSI,它将调用第三方应用程序作为安装过程的一部分。我可以让应用程序执行,但是它会在后台打开,位于安装程序后面。有什么办法让应用程序出现在安装程序前面?从MSI启动的第三方应用程序显示在后台

有问题的应用程序需要提升权限,因此从“完成”对话框运行它不是一个选项。

回答

0

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

How To: Run the Installed Application After Setup

+0

您的建议让我可以使用提升的特权从“完成”对话框运行应用程序,非常感谢。不幸的是,它并没有解决我的问题:新的应用程序有时仍然在另一个窗口后面启动。 – 2014-10-02 15:29:37

+0

你可以修改你的应用程序在启动时到达前台吗? – 2014-10-02 16:09:56

+0

恐怕不是我的应用程序。我想我可以编写自己的包装来到前台,然后启动应用程序,但如果可能的话,我想避免那种杂技。 – 2014-10-02 17:31:31

0

我刚刚想通做到这一点的最好办法。我从多个来源拼凑在一起。这是C#自定义操作启动一个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; 

} 
相关问题