I guess I’ve been doing a fair bit of scripting recently – admittedly nowhere near as much as I did back in my dev days, but there’s always something you learn new. I don’t even have a specific use for this, neither was I able to imagine a practical situation I could find for its’ potential use it, but who knows who’s reading this….?
Generally, in a VBScript I would have used the MsgBox function to display a dialog. Although I’ve also used the WScript.Shell object a fair few times, I’ve never had need to use the “Popup” method to also display a dialog when MsgBox was to hand without instantiating another object if you didn’t need it.
However, purely by accident I was looking at the documentation for WScript.Shell and found that “Popup” can do one thing “MsgBox” can’t – it can be dismissed automatically by a timer. Here’s a quick code example which shows how it works. Cut and paste into “dialogs.vbs” and run it. Two identical dialogs will be displayed, it’s just that the second one will dismiss after 2 seconds.
Dim szTitle ‘ Title for dialog
Dim szMessage ‘ Message to go in dialog
Dim iFeatures ‘ What options on dialog
Dim iSeconds ‘ How long to display for 🙂
Dim oShell ‘ For Popup Method
szTitle = “Sample Title”
szMessage = “Do you know you could do this?”
iFeatures = vbOKCancel or vbQuestion
iSeconds = 2
set oShell = CreateObject(“Wscript.Shell”)
msgbox szMessage, iFeatures, szTitle
oShell.Popup szMessage, iSeconds , szTitle, iFeatures
BTW – setting iSeconds to 0, or running “oShell.Popup szMessage,,szTitle,iFeatures” will produce identical functionality to msgbox. Even if you too can’t see a use, it’s one of those things to keep in your back-pocket for your next geeks outing under the banner of “Bet you didn’t know how to….”