如何让批处理/powershell MessageBox 和InputBox 窗口始终显示在其他窗口之上?

问题描述 投票:0回答:1

我正在编写一个批处理脚本来打开一系列 MessageBox 和 InputBox 窗口。该程序在首次启动时运行良好,并且用户能够与窗口交互,但是如果他们单击任何其他程序,则会将它们带到前台并基本上隐藏消息/输入框。这是两个框的示例,如何在使用程序时将它们始终保持在其他窗口的顶部?

powershell -Command "& {Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.Interaction]::InputBox(\"`r`nEnter the unique component number:`r`n\", 'Component Number')}" > %TEMP%\uniqueno1.tmp
set /p UniqueNo1=<%TEMP%\uniqueno1.tmp

powershell [Reflection.Assembly]::LoadWithPartialName("""System.Windows.Forms""");[Windows.Forms.MessageBox]::show(\"Unique Component Number %UniqueNo1%`r`n`r`n Click OK on this window to continue\", 'Component Number',0)>nul

powershell batch-file messagebox inputbox
1个回答
0
投票

试试这个:

powershell [Reflection.Assembly]::LoadWithPartialName("""System.Windows.Forms""");[Windows.Forms.MessageBox]::show(\"Unique Component Number %UniqueNo1%`r`n`r`n Click OK on this window to continue\", 'Component Number',0,0,0,131072)>nul

标志枚举 131072 代表 DefaultDesktopOnly。

请参阅 https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messageboxoptions?view=windowsdesktop-7.0

替代方案可能是

(new-object System.Windows.Window -Property @{TopMost = true})

powershell [Reflection.Assembly]::LoadWithPartialName("""System.Windows.Forms""");[Windows.Forms.MessageBox]::show((New-Object System.Windows.Forms.Form -Property @{TopMost = $true }),\"Unique Component Number %UniqueNo1%`r`n`r`n Click OK on this window to continue\", 'Component Number',0)>nul

但这对我不起作用。也许它应该以其他方式使用,不知道。

© www.soinside.com 2019 - 2024. All rights reserved.