2

While searching here, I came across this code on another question:

(echo MsgBox "Line 1" ^& vbCrLf ^& "Line 2",262192, "Title")> File.vbs
start File.vbs

It worked for me. My problem is, it is expecting user to click "OK" button to close. I want it to auto-close after 5 or 10 (or any predetermined number of) seconds.

I searched for "vbs" "close window" and few variations but ended up with nothing. Is there a way I can accomplish this purpose of mine ?

MelBurslan
  • 1,394

2 Answers2

3

Assuming that:

  1. You aren't interested in knowing if the window timed out
  2. You aren't interested in knowing what button the user clicked on
  3. You don't mind writing out a temporary VBScript file to generate the popup (and then removing it after)

then use the following:

echo WScript.CreateObject("Wscript.Shell").Popup "Line 1" ^& vbCrLf ^& "Line 2", 10, "Title", 262192 > %temp%\File.vbs
wscript %temp%\File.vbs
del /f %temp%\File.vbs

This will cause a pop-up to appear which has two lines of content ("Line 1" followed by "Line 2"), the title "Title", an exclamation icon, an OK button and a timeout of 10 seconds.

Further details on how to configure this window can be found in the documentation for the Popup command.

It’s worth noting that you can achieve an exclamation mark and an “OK” button with 48 instead of 262192 (which, technically, isn’t a valid numerical option).

Richard
  • 6,420
0

Create a .vbs script that invokes the Windows Script Host popup() method. That method has a parameter that determines how long the popup message window is shown. Then invoke your script from the command line with "wscript your_script.vbs".

FYI, there are abundant reports of popup() method timing being erratic, and even failing to timeout at all, especially with larger timeout values.

kreemoweet
  • 4,742