在所有其他窗口顶部显示任务计划程序的消息框

在所有其他窗口顶部显示任务计划程序的消息框

有没有一种好的方法可以让消息框在预定的时间弹出到其他窗口的顶部?默认的“显示消息”操作毫无用处地出现在其他所有操作的下方。

答案1

msg像这样使用 Windows 的内置命令怎么样?

msg * "Message you would like to send"

您可以添加其他参数,例如,/TIME:x其中 x 是您希望消息显示的秒数。当然,msg /?会向您显示所有可用选项。

这意味着 Windows XP 及更高版本是您要显示消息的系统。如果您拥有适用操作系统的家庭版,那么您就没那么幸运了。请参阅http://ss64.com/nt/msg.html了解可用参数。

如果您有家庭版,以下批处理脚本将使用 VBSCript 的 PopUp 方法弹出一条消息:

@echo off
::See http://msdn.microsoft.com/en-us/library/x83z1d9f(v=vs.84).aspx
::for an explanation of the PopUp method
::

::Use the directory from whence script was called as working directory
set CWD=%~dp0

::Use a random file name for the temporary VBScript.
set usrmsg=%CWD%%random%.vbs

::First parameter is the timeout in seconds. 0 = wait forever
set _timeout=%~1

::Second parameter is the message, enclosed in quotes.
set _Message=%~2

::Third parameter is the title of the window, enclosed in quotes.
set _Title=%~3

::This last variable is used to display a button/icon on the window.
::Setting this to 4096 sets the window to Modal (on top of everything else)
set _nType=4160

::Create the temp script using the provided information.
ECHO Set wshShell = CreateObject( "WScript.Shell" )>%usrmsg%
ECHO wshShell.Popup "%_Message%" ^& vbCrLf, %_Timeout%, "%_Title%", %_nType%>>%usrmsg%

::Run the script.
WSCRIPT.EXE %usrmsg%

::Delete the script.
DEL %usrmsg%

::Exit the batch file
exit /b

希望这可以帮助!

添加:Gregg 在评论中提到,为了使其在 Windows 10 中正常工作,如果您希望消息在屏幕上停留的时间超过 60 秒,则必须使用“/time:0”。

答案2

另请参阅https://www.howtogeek.com/136894/how-to-create-popup-reminders-with-no-additional-software/。如果链接失效,我会在这里总结:

  1. 打开 Windows 任务计划程序(在开始菜单中搜索“任务计划程序”)
  2. 在“操作”下,单击“创建任务”
  3. 在“常规”选项卡中,确保选中“仅在用户登录时运行”,并且未选中“隐藏”
  4. 在“触发器”选项卡中,单击“新建”以设置消息触发的时间
  5. 在“操作”选项卡中,单击“新建”,并确保顶部选定的操作是“启动程序”
  6. 在“程序/脚本”中,输入 CMD
  7. 在“添加参数”中,复制并粘贴以下内容:

    /C TITLE [此处为标题] &ECHO.&ECHO.&ECHO [此处为留言] &ECHO.&ECHO.&TIMEOUT [超时]

  8. 将 [此处为你的标题] 和 [此处为你的讯息] 替换为你喜欢的文字(不包括括号)
  9. 将 [timeout] 替换为您希望消息在超时前等待的秒数,如果您不希望它超时,则替换为 -1(无论哪种方式,在控制台窗口处于焦点时按下键都会关闭它)
  10. 单击“确定”!

这将生成一个带有给定文本的控制台窗口,该文本将出现在当前窗口的顶部,但不会自动窃取焦点(您可以像往常一样继续与当前窗口进行交互)。

这是我找到的最佳解决方案,希望它能帮助到别人!

答案3

在 vbs 中使用msgbox如下:

Set filesys = CreateObject("Scripting.FileSystemObject") 
Set shell = CreateObject("Shell.Application")
Set wshShell = WScript.CreateObject( "WScript.Shell" )
PCName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
msgbox "Dear user on " & PCName & vbcrlf & " " & vbcrlf & "This is a message box on top of all other windows.", &h51000, "I am msgbox"
shell.Open "C:\Users"

代码&h51000将确保 msgbox 始终位于所有其他窗口的中心和上方。

如果您只想安排一个消息框,您可以简单地使用任务计划程序,有一个内置函数来安排一条消息。请参阅任务计划程序中[启动程序]的位置。

答案4

Display a Message已弃用,并且msg命令在 Windows 10 1703 中对我不起作用。我用它powershell来显示计划任务的消息框,将其用作参数定义动作时:

-WindowStyle hidden -Command "& {[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.MessageBox]::Show('<message body here>','<window title here>')}"

虽然很丑,但是却很有效。

相关内容