echo msgbox "Hey! Here is a message!" > %tmp%\tmp.vbs
wscript %tmp%\tmp.vbs
del %tmp%\tmp.vbs
如果我按任意键,上述消息框就会消失。我希望按下任意键时该框消失,但目前只有当我单击框中的某个位置时它才会消失。
我希望当该框出现时,任务栏中会显示简短的文本。
如果我按下任意按钮,我该怎么做才能让它消失?
答案1
尝试类似这样的纯批处理脚本,创建一个 HTA 文件,该文件有一个设置为自动关闭的计时器,该计时器被设置为顶部逻辑中的一个变量。
该脚本基本上为弹出窗口构建一个 HTA 文件,然后构建 VBS 文件,然后像您从该%tmp%
位置执行的操作一样调用它。
我无法想出另一种方法让 VBS 消息框省略该OK
按钮或任何其他按钮。
笔记: 只需在顶部设置变量,其余部分就会动态构建。如果您需要进一步调整而又无法弄清楚,请告诉我,一旦我看到,我就可以及时轻松地更新大部分内容。
批处理脚本示例
@ECHO ON
SET MsgTitle=Hey! Here is a Title!
SET MsgLine1=Hey! Here is a message!
SET MsgLine2=Message Line Two.
SET MsgLine3=Message Line Three.
::: -- Set the number in seconds you want the window to close
SET CloseTimer=5
SET TmpHTAFile=%tmp%\tmp.hta
SET TmpVBSFile=%tmp%\tmp.vbs
IF EXIST "%TmpHTAFile%" DEL /Q /F "%TmpHTAFile%"
IF EXIST "%TmpVBSFile%" DEL /Q /F "%TmpVBSFile%"
ECHO ^<html^> >> "%TmpHTAFile%"
ECHO ^<head^> >> "%TmpHTAFile%"
ECHO ^<hta:application >> "%TmpHTAFile%"
ECHO APPLICATIONNAME = "Message Alert" >> "%TmpHTAFile%"
ECHO ID = "Message Alert" >> "%TmpHTAFile%"
ECHO BORDERSTYLE = "Normal" >> "%TmpHTAFile%"
ECHO CAPTION = "No" >> "%TmpHTAFile%"
ECHO CONTEXTMENU = "No" >> "%TmpHTAFile%"
ECHO INNERBORDER = "No" >> "%TmpHTAFile%"
ECHO MAXIMIZEBUTTON = "No" >> "%TmpHTAFile%"
ECHO MINIMIZEBUTTON = "No" >> "%TmpHTAFile%"
ECHO NAVIGABLE = "No" >> "%TmpHTAFile%"
ECHO SCROLL = "No" >> "%TmpHTAFile%"
ECHO SCROLLFLAT = "No" >> "%TmpHTAFile%"
ECHO SELECTION = "No" >> "%TmpHTAFile%"
ECHO SHOWINTASKBAR = "No" >> "%TmpHTAFile%"
ECHO SINGLEINSTANCE = "Yes" >> "%TmpHTAFile%"
ECHO SYSMENU = "No"/^> ^<STYLE^> >> "%TmpHTAFile%"
ECHO html, body { >> "%TmpHTAFile%"
ECHO background color: #000000 >> "%TmpHTAFile%"
ECHO font-size: 90%; >> "%TmpHTAFile%"
ECHO line-height: 2.1em; >> "%TmpHTAFile%"
ECHO margin: 10; >> "%TmpHTAFile%"
ECHO padding: 0; >> "%TmpHTAFile%"
ECHO } >> "%TmpHTAFile%"
ECHO h1 {font-family: Arial; >> "%TmpHTAFile%"
ECHO color: #FF0000; >> "%TmpHTAFile%"
ECHO font-size: 3em; >> "%TmpHTAFile%"
ECHO text-align: center; >> "%TmpHTAFile%"
ECHO } >> "%TmpHTAFile%"
ECHO h2 {font-family: Arial; >> "%TmpHTAFile%"
ECHO color: #ffffff; >> "%TmpHTAFile%"
ECHO font-size: 1.5em; >> "%TmpHTAFile%"
ECHO text-align: left; >> "%TmpHTAFile%"
ECHO } >> "%TmpHTAFile%"
ECHO h3 >> "%TmpHTAFile%"
ECHO {font-family: Arial; >> "%TmpHTAFile%"
ECHO color: #666666; >> "%TmpHTAFile%"
ECHO font-size: 1em; >> "%TmpHTAFile%"
ECHO text-align: center; >> "%TmpHTAFile%"
ECHO } >> "%TmpHTAFile%"
ECHO ^</STYLE^> ^<script type='text/vbscript'^> Sub Window_onload() >> "%TmpHTAFile%"
ECHO me.ResizeTo 500,280 >> "%TmpHTAFile%"
ECHO me.MoveTo Screen.Width /2 - 300,Screen.Height / 2 - 300 >> "%TmpHTAFile%"
ECHO me.SetTimeout "Me.Close()",%CloseTimer%000 >> "%TmpHTAFile%"
ECHO End Sub >> "%TmpHTAFile%"
ECHO ^</script^> >> "%TmpHTAFile%"
ECHO ^</head^> >> "%TmpHTAFile%"
ECHO ^<body scroll="no"^> >> "%TmpHTAFile%"
ECHO ^<br^> >> "%TmpHTAFile%"
ECHO ^<h1^>%MsgTitle%^</h1^> >> "%TmpHTAFile%"
ECHO ^<h2^>%MsgLine1%^<br^> >> "%TmpHTAFile%"
ECHO %MsgLine2%^<br^> >> "%TmpHTAFile%"
ECHO %MsgLine3%^</h2^> >> "%TmpHTAFile%"
ECHO ^<h3^>close in %CloseTimer% seconds^</h3^> >> "%TmpHTAFile%"
ECHO ^<script type="text/javascript"^> >> "%TmpHTAFile%"
ECHO ^</script^> >> "%TmpHTAFile%"
ECHO ^</body^> >> "%TmpHTAFile%"
ECHO ^</html^> >> "%TmpHTAFile%"
ECHO Set objShell = Wscript.CreateObject("Wscript.Shell") >> "%TmpVBSFile%"
ECHO objShell.Run ("%TmpHTAFile%") >> "%TmpVBSFile%"
wscript "%TmpVBSFile%"
DEL /Q /F "%TmpVBSFile%"
资源: http://www.itninja.com/blog/view/how-to-create-a-customised-popup-notification-window-using-hta
示例批次(使用零秒参数)
(使用此方法似乎只会在您按下Enter或Space Bar它是活动窗口时关闭 VBS 消息框窗口)
ECHO msgbox "Hey! Here is a message!",0,"My Title!">"%tmp%\tmp.vbs"
WSCRIPT "%tmp%\tmp.vbs"
IF EXIST "%tmp%\tmp.vbs" DEL /Q /F "%tmp%\tmp.vbs"