Discussion:
PopUp problem in HTA
(too old to reply)
Dave "Crash" Dummy
2013-08-09 15:47:49 UTC
Permalink
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
2013-08-10 20:39:00 UTC
Permalink
| 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
2013-08-10 22:50:58 UTC
Permalink
Post by Mayayana
| Is there a solution or an alternative?
I usually just use labels that update with relevant
information, but I got curious and tried something
You need an HTA with a button.
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
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))
Thanks you. I will play with it.
--
Crash

I'm going to be a dirty old man when I grow up.
n***@gmail.com
2013-08-24 23:18:28 UTC
Permalink
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
Dave "Crash" Dummy
2013-08-25 18:14:01 UTC
Permalink
Post by n***@gmail.com
Function ShellPopup(Message,Seconds,PopupTitle,Buttons)
Set System = CreateObject("Scripting.FileSystemObject") TempFile =
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.
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
2014-10-02 08:13:13 UTC
Permalink
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.
2014-10-02 09:33:33 UTC
Permalink
Post by Bryan Spillman
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
2014-10-02 13:57:53 UTC
Permalink
|
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
2014-10-02 14:01:11 UTC
Permalink
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
2014-10-03 08:22:34 UTC
Permalink
Post by Bryan Spillman
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
2014-10-03 14:41:29 UTC
Permalink
| 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
2014-10-03 15:21:47 UTC
Permalink
Post by Mayayana
| 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.
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 ~
n***@gmail.com
2013-08-24 23:19:54 UTC
Permalink
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
Bryan Spillman
2014-10-04 11:05:16 UTC
Permalink
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 :)
Post by Dave "Crash" Dummy
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
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
2014-10-04 13:03:32 UTC
Permalink
| 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
2014-10-04 14:32:16 UTC
Permalink
This post might be inappropriate. Click to display it.
Mayayana
2014-10-04 15:00:48 UTC
Permalink
This post might be inappropriate. Click to display it.
Dave "Crash" Dummy
2014-10-04 15:24:46 UTC
Permalink
Post by Bryan Spillman
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.
--
Crash

Committed to the search for intraterrestrial intelligence.
Loading...