我不知道 Jenkins,但这里有一个 PowerShell 函数,它显示一个消息框,该消息框将在指定的超时间隔(以毫秒为单位)后消失。不会阻止此弹出窗口。
function Show-Messagebox
{
param([String]$Title, [String]$Message, [Int]$TimeOut=2000)
$TypeDef = @'
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class Win32API
{
private const UInt32 WM_CLOSE = 0x0010;
[DllImport("user32.dll", EntryPoint="FindWindow", SetLastError = true)]
private static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);
[DllImport("user32.Dll")]
private static extern int PostMessage(IntPtr hWnd, UInt32 msg, int wParam, int lParam);
public static void ShowMessageBox(string Message, string Caption, int TimeOut = 2000)
{
var timer = new System.Timers.Timer(TimeOut) { AutoReset = false };
timer.Elapsed += delegate
{
IntPtr hWnd = FindWindowByCaption(IntPtr.Zero, Caption);
if (hWnd.ToInt32() != 0) PostMessage(hWnd, WM_CLOSE, 0, 0);
};
timer.Enabled = true;
MessageBox.Show(Message, Caption);
}
}
'@
Add-Type -TypeDefinition $TypeDef -ReferencedAssemblies System.Windows.Forms
[Win32API]::ShowMessageBox($Message, $Title, $TimeOut)
}
函数可以这样调用:
Show-Messagebox -Title "The Title" -Message "The complete message"
在 C# 代码中将类的整个类型定义作为 here 字符串放入函数中有点笨拙(此处字符串的结束标记 '@ 之前不允许有空格)但它仍然很简单复制和粘贴解决方案。
如果您将 PoweShell 脚本中的 [System.Windows.Forms.MessageBox]::Show() 调用替换为此函数,则不应再出现阻塞消息框。