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

Mos*_*oss 13 windows window task-scheduler

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

JSa*_*hez 13

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

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
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!

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

  • 除非您指定`/TIME:0`,FYI msg 将在 60 秒后自动关闭。这是在 Win10 x64 v1607 Enterprise LTSB 上。我想知道为什么我的脚本测试得很好,但是当我放入 Task Scheduler 时我从未收到消息。可耻的插件:https://serverfault.com/a/931932/131761 (2认同)

小智 6

另请参阅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. 点击“确定”!

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

这是我找到的最好的解决方案,希望它可以帮助某人!