Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PopUp problem in HTA

1,039 views
Skip to first unread message

Dave "Crash" Dummy

unread,
Aug 9, 2013, 11:47:49 AM8/9/13
to
I want to use a popup in a HTA script that closes automatically after a
few seconds. The WshShell.PopUp method works fine in VBS, but stays
open until I click a button in HTA. This is the test code I am using:

Set WshShell = CreateObject( "WScript.Shell" )
rt=WshShell.PopUp("Pause",2)

Is there a solution or an alternative?
--
Crash

"Never apologize. It's a sign of weakness."
~ Leroy Jethro Gibbs ~

Mayayana

unread,
Aug 10, 2013, 4:39:00 PM8/10/13
to
| Is there a solution or an alternative?

I usually just use labels that update with relevant
information, but I got curious and tried something
out. This seems to work:

You need an HTA with a button.
In the HTA script block is this:

Sub ButTestPop_onclick()
'-- quotes required. Otherwise string is clipped at first space.
TestPop Chr(34) & "Here's a popup run externally|2|Popup Test" & Chr(34)
End Sub

Sub TestPop(sOptions)
Dim Ret, SH
Set SH = CreateObject("WScript.Shell")
Ret = SH.Run("pop1.vbs " & sOptions, , False)
Set SH = Nothing
End Sub

Then you need a file in the same location named
pop1.vbs, containing this:

Dim SH, rt, Arg, A1
Set SH = CreateObject("WScript.Shell")
Arg = WSCript.Arguments(0)
A1 = Split(Arg, "|")
If Ubound(A1) <> 2 then wscript.quit
rt = SH.PopUp(A1(0), A1(1), A1(2))



Dave "Crash" Dummy

unread,
Aug 10, 2013, 6:50:58 PM8/10/13
to
Thanks you. I will play with it.
--
Crash

I'm going to be a dirty old man when I grow up.
Message has been deleted

nick....@gmail.com

unread,
Aug 24, 2013, 7:19:54 PM8/24/13
to
Function ShellPopup(Message,Seconds,PopupTitle,Buttons)

Set System = CreateObject("Scripting.FileSystemObject")
TempFile = System.GetSpecialFolder(2).path & "\@PopUp#.vbs"
Set File = System.CreateTextFile(TempFile)
File.WriteLine "set Shell = CreateObject(""Wscript.Shell"")"
File.WriteLine "WScript.Quit Shell.Popup(""" & Message &_
"""," & Seconds & ",""" & PopUpTitle &_
"""," & Buttons & ")"
File.Close
ShellPopup = CreateObject("Wscript.Shell").Run(TempFile,1,True)
System.DeleteFile TempFile,True

End Function


Hope this helps :)
Just paste it below your script and dont forget to put a variable for the function.

Example:


WRONG =
--------------------------------------------------------------------
Sub Window_onLoad

window.resizeTo 500,500
ShellPopup("Program started", 3, "Start", 0)

End Sub
--------------------------------------------------------------------

GOOD =

Sub Window_onLoad

window.resizeTo 500,500
WindowPopup = ShellPopup("Program started", 3, "Start", 0)

End Sub

Dave "Crash" Dummy

unread,
Aug 25, 2013, 2:14:01 PM8/25/13
to
nick....@gmail.com wrote:
> Function ShellPopup(Message,Seconds,PopupTitle,Buttons)
>
> Set System = CreateObject("Scripting.FileSystemObject") TempFile =
> System.GetSpecialFolder(2).path & "\@PopUp#.vbs" Set File =
> System.CreateTextFile(TempFile) File.WriteLine "set Shell =
> CreateObject(""Wscript.Shell"")" File.WriteLine "WScript.Quit
> Shell.Popup(""" & Message &_ """," & Seconds & ",""" & PopUpTitle &_
> """," & Buttons & ")" File.Close ShellPopup =
> CreateObject("Wscript.Shell").Run(TempFile,1,True) System.DeleteFile
> TempFile,True End Function
>
>
> Hope this helps :) Just paste it below your script and dont forget to
> put a variable for the function.
>
> Example:
>
>
> WRONG =
> --------------------------------------------------------------------
> Sub Window_onLoad
>
> window.resizeTo 500,500 ShellPopup("1", "Program started", 3,
> "Start", 0) End Sub
> --------------------------------------------------------------------
>
> GOOD =
>
> Sub Window_onLoad
>
> window.resizeTo 500,500 WindowPopup = ShellPopup("1", "Program
> started", 3, "Start", 0) End Sub

Thank you. That looks very similar to Mayayana's solution, both create
an external VBS program to host the popup operation.
--
Crash

I brake for 'possums.

Bryan Spillman

unread,
Oct 2, 2014, 4:13:15 AM10/2/14
to

Evertjan.

unread,
Oct 2, 2014, 5:33:33 AM10/2/14
to
Bryan Spillman <jbspi...@gmail.com> wrote on 02 okt 2014 in
microsoft.public.scripting.vbscript:

> http://blogs.technet.com/b/heyscriptingguy/archive/2006/07/27/how-can-i-d
> isplay-a-message-box-that-has-no-buttons-and-that-disappears-after-a-spec
> ified-period-of-time.aspx

All messageboxes disappear after a period of time,
you don't even have to set the time.
Some of them could be found later in the attic.

However I would use the DOM and CSS
[and Javascript, which works well in HTa]:

===========================
<HTA:APPLICATION ID="oHTA" APPLICATIONNAME="Demo" WindowState="maximize">
<html>
<style type='text/css'>
#mbx {display:none;position:absolute;left:200px;top:200px;
width:150px;height:40px;border:4px #f77 solid;
padding:15px 50px;background-color:#fee;}
.show {display:block!important;}
</style>
<script type='text/javascript'>
function show(secs) {
document.getElementById("mbx").className="show";
setTimeout(hide,secs*1000);
}
function hide() {
document.getElementById("mbx").className="";
};
</script>
<body>
<div id=mbx class=''>myMessage</div>
<button onclick='show(1)'>show me</button>
===========================


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Mayayana

unread,
Oct 2, 2014, 9:57:53 AM10/2/14
to
|
http://blogs.technet.com/b/heyscriptingguy/archive/2006/07/27/how-can-i-display-a-message-box-that-has-no-buttons-and-that-disappears-after-a-specified-period-of-time.aspx

No one should have to suffer through the tedious,
condescending hamminess of "The Scripting Guys". :)

I don't see the original thread here, so forgive me if
I'm repeating anything.

Your post seems ambiguous. The title is about showing
a message in an HTA. The SG post is about showing a
custom message *in a script* by loading an HTA.

For a custom message in a script I
use a class. It's more involved than what the SG are
showing, but their code would also be very complex
once you actually flesh it out to work properly. (Also,
if it's in a script you can always use WScript.Sleep.
The custom message is the hard part, not the timer.)
See here for custom message windows that can be
controlled from within the script:

http://www.jsware.net/jsware/msggal.php5

There's a link at the bottom for the download. You
just paste the class into a script and then you can
show any sort of custom message you like.

If the message is to show in an HTA itself you
can use CSS, though it might take some fiddling
to get it to look just the way you want it. And
be sure to leave out the DOCTYPE tag if you want
it consistent in different IE versions. (Also, IE 11
does not recognize VBS in standards mode, which
is another reason to leave out DOCTYPE, using
quirks mode):

<html>
<STYLE>
#msg {position: absolute; top: 200px; left: 200px; width: 200px;
height: 100px; background-color: #FF0000; color: #FFFFFF;
font-family: verdana; font-size: 13px; text-align: center; padding:
20px;
border-style: outset; border-width: 1px; display: none;}
</STYLE>

<script language = "VBScript">
Sub But1_onclick()
ShowMsg "This is an alert", 4
End Sub

Sub ShowMsg(sMsg, LSec)
Dim s1
s1 = "msg.style.display = " & Chr(34) & "none" & Chr(34)
msg.innerText = sMsg
msg.style.display = "block"
msg.style.zIndex = 100
window.setTimeout s1, LSec * 1000, "VBScript"
End Sub
</script>

<body>

<DIV ID="msg"> </DIV>
<INPUT ID="But1" TYPE="button" VALUE=Show Message">
</body>
</html>


Mayayana

unread,
Oct 2, 2014, 10:01:11 AM10/2/14
to
PS - I didn't mean to imply that you can't use a
custom message box in an HTA. That works fine
and can be easily called from an external script
if desired. I was just pointing out that script and
CSS within a webpage is also very flexible. Either
way, what the SG conveniently leave out is that
you'll need some experience with CSS and webpage
layout if you want a nice-looking message window.
That's why I wrote the custom message box class --
to encapsulate all the work of making the window
look presentable.


Dave "Crash" Dummy

unread,
Oct 3, 2014, 4:22:34 AM10/3/14
to
Bryan Spillman wrote:
> http://blogs.technet.com/b/heyscriptingguy/archive/2006/07/27/how-can-i-display-a-message-box-that-has-no-buttons-and-that-disappears-after-a-specified-period-of-time.aspx

Evertjan and Mayayana show how to create a buttonless, temporary popup
within a HTA script. Here is a way to use HTA to create a custom popup
that is callable from a VBScript file (VBS).

'---------------------------------popup.hta------------------------------
<HTA:APPLICATION ID="oHTA" caption="no" scroll="no" />
<html><body></body>
<script type="text/vbscript">
'.............reduce in size and move to middle of screen
window.resizeTo 200,100
window.moveTo (screen.availWidth-200)/2,(screen.availHeight-100)/3

'............retrieve popup message from command line
cmd=oHTA.commandline
msg=split(cmd,"/")(1)
document.body.innerText=msg

'.............automatically close after 3 second delay
setTimeout "window.close",3000

'.............optional close on click
sub document_onClick()
window.close
end sub
</script>
</html>

Here is the code to call the popup with a passed message.
'---------------------------------demo.vbs-----------------------------
Set WshShell = CreateObject("WScript.Shell")
msg="Hello, World!"
WshShell.Run "popup.hta /" & msg

The same code could be used within another HTA file to call the popup,
but Evertjan and Mayayana already offer better ways.
--
Crash

Committed to the search for intraterrestrial intelligence.

Mayayana

unread,
Oct 3, 2014, 10:41:29 AM10/3/14
to
| Evertjan and Mayayana show how to create a buttonless, temporary popup
| within a HTA script. Here is a way to use HTA to create a custom popup
| that is callable from a VBScript file (VBS).
|

I'm guessing you didn't read the link. Your sample
is essentially what the Scripting guys posted. Though
even your quickie sample was better than the SG version.
When their code is run it produces a default size browser
window with a standard border but no chrome. They
conveniently avoid the major work of making custom
popups: the graphical display details.


The OP's post was confusing. He's offering an example
of an HTA msgbox to call from script, but the title is
"popup problem in HTA".

I cleaned out my .dbx newsgroup files recently,
so I can't see whether Bryan Spillman was
misunderstanding a current discussion or whether
he's just one of those Google Groupies wandering
around answering 10-year-old questions willy nilly
because he doesn't know what Usenet is. He did
post via GG, and he hasn't responded, so I'm
guessing we might be talking to ourselves. :)

I'd be tempted to try to block all GG postings, but
I figure that these discussions will get reposted on
various sites, so they could still end up being useful
to others.


Dave "Crash" Dummy

unread,
Oct 3, 2014, 11:21:47 AM10/3/14
to
I read the article. but I was disgusted with it before I reached the last
paragraph, where SG shows how to call the popup. He doesn't give any
information on how to pass a message for it, which is the point of my
posting. My actual working script allows for passing the delay time as
well as the message, and is designed to emulate a regular script msgbox.
--
Crash

"When you want to fool the world, tell the truth."
~ Otto von Bismarck ~

Bryan Spillman

unread,
Oct 4, 2014, 7:05:21 AM10/4/14
to
oh i am here, using GG. I am quite the fan of HTA's and have been writing them for years. Waiting for a way to embed items other than vbscript in the code :)

Mayayana

unread,
Oct 4, 2014, 9:03:32 AM10/4/14
to
| oh i am here, using GG. I am quite the fan of HTA's and have been writing
them for years. Waiting for a way to embed items other than vbscript in the
code :)
|
| On Friday, August 9, 2013 11:47:49 AM UTC-4, Dave Crash Dummy wrote:

Yet you didn't notice that you were replying to a
post that was more than a year old?

What do you mean by "items other than VBScript".
You can have images. You can have ActiveX controls.
You can do nearly anything compiled software can do.
What else would you need?


Dave "Crash" Dummy

unread,
Oct 4, 2014, 10:32:16 AM10/4/14
to
Mayayana wrote:
> | oh i am here, using GG. I am quite the fan of HTA's and have been
> writing them for years. Waiting for a way to embed items other than
> vbscript in the code :) | | On Friday, August 9, 2013 11:47:49 AM
> UTC-4, Dave Crash Dummy wrote:
>
> Yet you didn't notice that you were replying to a post that was more
> than a year old?

Ain't that a bitch! I was the original poster and eventually answered my
own question! Gimme a break. That was a year ago, and I have trouble
remembering last week!

> What do you mean by "items other than VBScript". You can have images.
> You can have ActiveX controls. You can do nearly anything compiled
> software can do. What else would you need?

Since HTA is basically IE displaying HTML, it is restricted to the same
client side scripting languages, namely VBScript and JScript. Other
languages can be "embedded" by running external scripts or executables
with the "run" command, just as external HTA scripts can be run from VBS.
--
Crash

"Facts are stubborn things, but statistics are more pliable."
~ Laurence J. Peter ~

Mayayana

unread,
Oct 4, 2014, 11:00:48 AM10/4/14
to
| > Yet you didn't notice that you were replying to a post that was more
| > than a year old?
|
| Ain't that a bitch! I was the original poster and eventually answered my
| own question! Gimme a break. That was a year ago, and I have trouble
| remembering last week!
|

More than once I've found an answer to one of my
questions in a posting made to a newsgroup by myself,
some years earlier. Part of the reason I write utilities and
make them public is so that I'll have the code and the
explanation later, when I've forgotten all the details. :)



Dave "Crash" Dummy

unread,
Oct 4, 2014, 11:24:46 AM10/4/14
to
Bryan Spillman wrote:
> oh i am here, using GG. I am quite the fan of HTA's and have been
> writing them for years. Waiting for a way to embed items other than
> vbscript in the code :)

You already can, if you have a compatible host installed. I have Perl
installed and can embed PerlScript in both HTML and HTA files. They will
only work on machines that have Perl installed, of course.
0 new messages