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

Possible to time out a popup?

311 views
Skip to first unread message

DE

unread,
Feb 28, 2004, 10:35:20 AM2/28/04
to
Hi,

A question I've been thinking of for some time... I am
sure I saw the answer somewhere on the web but can't find
it again...

I am trying to display a popup box that times out. I know
it can be done with the wscript.shell popup command by
just specifying the timeout time as one of the paramters,
however I want some message box to keep updating the
amount of time left as text IN the popup box and somehow
loop it so it doesn't allow user interaction until the
timeout expires. My instinct tells me this can only be
done through scripting something with IE (form), but I am
sure I saw this done somewhere with either msgbox or popup
within somekind of a loop to keep updating the
msgbox/popup text on the fly. Any help would be great!

Thanks

Joe Earnest

unread,
Feb 28, 2004, 11:26:25 AM2/28/04
to
Hi,

"DE" <anon...@discussions.microsoft.com> wrote in message
news:057d01c3fe10$7914e450$3a01...@phx.gbl...

If I understand what you're asking for, this may get you started. The first
form uses the popup box. The popup refreshes every 2 seconds. The example
has a 10-second duration. User dismissal simply refreshes, and the box is
system-modal. You need to add an exit condition to exit an indefinite loop.

The second form is an IE progress bar form and is much smoother. Using use
kiosk style (reduced fullscreen with larger outset borders takes care of
titlebar and taskbar closures, but any IE dialog can be closed with Alt+F4,
which cannot be effectively trapped for security reasons. Since dismissal
will create an error, the script below simply to traps the error and
regenerates the box. Another approach is to use GetRef to sink an
OnBeforeUnload event that accomplishes the same thing, but error-trapping
seems easier to me. The modified handling code at the bottom of the sample
code moves the dialog box to a function to facilitate regeneration and sets
up your operational loop. If you want a counter instead of a bar, simply
count in the same way as the Popup example, and use InnerText to insert the
count into a bordered cell or a read-only input-text control box.

With either example, try dismissing the box and see what happens.

---
Popup
---
set oWshShell= createobject("wscript.shell")
nDisplayTime= 10
nPopupTime= 2
nStartTime= timer
nLapseTime= 0

do
oWshShell.popup "Elapsed time: " _
& nLapseTime & " seconds " _
& vbCr & vbCr & "Please wait ...", _
nPopupTime, "Title of Box", _
vbOkOnly +vbInformation +vbSystemModal

' if ... then exit do

nLapseTime= cint(timer -nStartTime)
if (nLapseTime<0) then
nStartTime= nStartTime _
-(60 *60 *24)
nLapseTime= cint(timer -nStartTime)
end if

loop while (nLapseTime<nDisplayTime)

msgbox "Process complete. ", _
vbOkOnly +vbInformation, _
"Title of Box"
---

---
IE Progress Bar
---
nScrW= createobject( _
"htmlfile").parentWindow.screen.availWidth
nScrHt= createobject( _
"htmlfile").parentWindow.screen.availHeight

showBar oIe
wscript.sleep 1000

oIe.document.parentWindow.document.script.barop 0

do 'your operational loop

' ...

iPct= iPct +1 'or whatever increment

on error resume next
oIe.document.parentWindow.document.script.barop iPct
if err then
err.clear
showBar oIe
oIe.document.parentWindow.document.script.barop iPct
end if
on error goto 0

loop until (iPct=100)

wscript.sleep 1000
wscript.echo "Script is complete."

oIe.quit
wscript.quit

function showBar (oIe)

set oIe= createobject( _
"internetExplorer.application")
oIe.navigate("about:blank")
do: wscript.sleep 50: loop until oIe.readyState=4

with oIe
.fullScreen= true
.toolbar = false
.statusBar = false
.addressBar = false
.resizable= false
.width= 420
.height= 120
.left= (nScrW -420) \2
.top= (nScrHt -120) \2

with .document
.writeLn ("<!doctype html public>")
.writeLn ("<html style=""border-style:outset;" _
& "border-width:4px"">")
.writeln ("<head>")
.writeLn ("<title>Progress Bar Demo</title>")
.writeln ("<style type=""text/css"">")
.writeln ("body {background-color:#ece9d8;" _
& "text-align:center;vertical-align:middle}")
.writeln ("</style>")
.WriteLn ("<script language=""vbscript"">")
.writeln ("function BarOp (vnPct)")
.writeln ("window.bar.style.width= vnPct & ""%""")
.writeln ("end function")
.writeln ("</script>")
.writeln ("</head>")
.writeln ("<body scroll=""no"">")
.writeln ("<table>")
.writeln ("<tr>")
.writeln ("<td style=""text-align:center;" _
& "font-family:Arial;font-size:16pt;" _
& "font-weight:bold"">")
.writeln ("Progress Bar Demo")
.writeln ("</td>")
.writeln ("</tr>")
.writeln ("<tr>")
.writeln ("<td id=""barcell"" " _
& "style=""width:400px;padding-left:7px;" _
& "padding-right:7px;text-align:left;" _
& "border-style:inset;border-width:thin;" _
& "background-color:navajowhite"">")
.writeln ("<hr id=""bar"" " _
& "style=""width:0%;height:15px;" _
& "color:darkblue"" />")
.writeln ("</td>")
.writeln ("</tr>")
.writeln ("</table>")
.writeln ("</body>")
.writeln ("</html>")
end with
end with

oIe.Visible= True

end function
---

Joe Earnest

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.564 / Virus Database: 356 - Release Date: 01-19-04


DE

unread,
Feb 28, 2004, 11:56:22 AM2/28/04
to
Thanks,

The progress bar is nice, however I was looking more
towards what you were doing with the first example except
that I thought there was a way to somehow automatically
refresh the number of seconds text within the box without
event needing user intervention as well as to keep that
box up until process/script activity is complete.

Like I said before, I really doubt that there is a way
without using some kind of IE object like you did with the
second example, but I could of sworn I saw it somewhere.

D

>.
>

Joe Earnest

unread,
Feb 28, 2004, 12:15:48 PM2/28/04
to
Hi,

"DE" <anon...@discussions.microsoft.com> wrote in message

news:39f601c3fe1b$cb2b98f0$a401...@phx.gbl...


| Thanks,
|
| The progress bar is nice, however I was looking more
| towards what you were doing with the first example except
| that I thought there was a way to somehow automatically
| refresh the number of seconds text within the box without
| event needing user intervention as well as to keep that
| box up until process/script activity is complete.
|
| Like I said before, I really doubt that there is a way
| without using some kind of IE object like you did with the
| second example, but I could of sworn I saw it somewhere.

No way to refresh inside the Popup. It must be dismissed and restarted.
Here's the IE example with countdown text (10 second total, refresh every
second -- the first second may be jumped while the box is set up, depending
on your system). You can take out the progress bar, if you don't want it.

---
nDisplayTime= 10
nStartTime= clng(timer)
sMsg= (nDisplayTime) _
& " seconds remaining"

nScrW= createobject( _
"htmlfile").parentWindow.screen.availWidth
nScrHt= createobject( _
"htmlfile").parentWindow.screen.availHeight

showBar oIe
wscript.sleep 1000

oIe.document.parentWindow.document.script.barop 0

do 'your operational loop

' ...

nElapsedTime= cint(timer- nStartTime)
if (nElapsedTime<0) then
nStartTime= nStartTime -(60 *60 *24)
nElapsedTime= clng(timer- nStartTime)
end if

if (nElapsedTime>nLastTime) then
iPct= cint((nElapsedTime /nDisplayTime) *100)
sMsg= (nDisplayTime -nElapsedTime) _
& " seconds remaining"
nLastTime= nElapsedTime

on error resume next
oIe.document.parentWindow.document.script.barop iPct

if (err=0) then
oIe.document.all.msgcell.innerText= sMsg
end if

if err then
err.clear
showBar oIe
oIe.document.parentWindow.document.script.barop iPct

oIe.document.all.msgcell.innerText= sMsg
end if


end if
on error goto 0

loop until (nElapsedTime=nDisplayTime)

wscript.sleep 1000
wscript.echo "Script is complete."

oIe.quit
wscript.quit

function showBar (oIe)

set oIe= createobject( _
"internetExplorer.application")
oIe.navigate("about:blank")
do: wscript.sleep 50: loop until oIe.readyState=4

with oIe
.fullScreen= true
.toolbar = false
.statusBar = false
.addressBar = false
.resizable= false
.width= 420

.height= 160


.left= (nScrW -420) \2
.top= (nScrHt -120) \2

with .document
.writeLn ("<!doctype html public>")
.writeLn ("<html style=""border-style:outset;" _
& "border-width:4px"">")

.writeLn ("<head>")


.writeLn ("<title>Progress Bar Demo</title>")

.writeLn ("<style type=""text/css"">")
.writeLn ("body {background-color:#ece9d8;" _
& "text-align:center;" _
& "vertical-align:middle}")
.writeLn ("</style>")
.writeLn ("<script language=""vbscript"">")
.writeLn ("function BarOp (vnPct)")


.writeln ("window.bar.style.width= vnPct & ""%""")

.writeLn ("end function")
.writeLn ("</script>")
.writeLn ("</head>")
.writeLn ("<body scroll=""no"">")
.writeLn ("<table>")
.writeLn ("<tr>")
.writeLn ("<td style=""text-align:center;" _


& "font-family:Arial;font-size:16pt;" _
& "font-weight:bold"">")

.writeLn ("Progress Bar Demo")
.writeLn ("</td>")
.writeLn ("</tr>")
.writeLn ("<tr>")
.writeLn ("<td id=""barcell"" " _
& "style=""width:400px;" _
& "padding-left:7px;" _
& "padding-right:" _
& "7px;text-align:left;" _
& "border-style:inset;" _
& "border-width:thin;" _
& "background-color:navajowhite"">")
.writeLn ("<hr id=""bar"" " _


& "style=""width:0%;height:15px;" _
& "color:darkblue"" />")

.writeLn ("</td>")
.writeLn ("</tr>")
' .writeLn ("<tr>")
' .writeLn ("<td>")
' .writeLn ("<br /><br />")
' .writeLn ("</td>")
' .writeLn ("</tr>")
.writeLn ("<tr>")
.writeLn ("<td id=""msgcell"" " _
& "style=""width:400px;" _
& "text-align:center;" _
& "font-family:Arial;font-size:12pt;" _
& "font-weight:bold;" _
& "border-style:inset;" _
& "border-width:thin"">")
.writeLn (sMsg)
.writeLn ("</td>")
.writeLn ("</tr>")
.writeLn ("</table>")
.writeLn ("</body>")
.writeLn ("</html>")
end with
end with

oIe.visible= true

DE

unread,
Feb 28, 2004, 12:20:23 PM2/28/04
to
Guess I was wrong...The progress bar looks good! Is there
a way to keep it as system modal...that is make that
progress bar run, and no other app. touchable until
finished?
>.
>

Torgeir Bakken (MVP)

unread,
Feb 28, 2004, 12:42:35 PM2/28/04
to
DE wrote:

> The progress bar is nice, however I was looking more
> towards what you were doing with the first example except
> that I thought there was a way to somehow automatically
> refresh the number of seconds text within the box without
> event needing user intervention as well as to keep that
> box up until process/script activity is complete.
>
> Like I said before, I really doubt that there is a way
> without using some kind of IE object like you did with the
> second example, but I could of sworn I saw it somewhere.

Hi

Correct, there is nothing builtin for this that you can use from a
script, you either need to use the IE object or a 3rd party component.

For some free 3rd party controls that you can use from a VBScript, take
a look at e.g. the "non-modal" links here:

http://home.att.net/~wshvbs/#wshLtWtNonModalDlg


By the way, a very nice progress bar you have created there, Joe :-)

--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter


Joe Earnest

unread,
Feb 28, 2004, 12:59:53 PM2/28/04
to
Hi,

"DE" <anon...@discussions.microsoft.com> wrote in message

news:3afa01c3fe1f$26351480$a301...@phx.gbl...


| Guess I was wrong...The progress bar looks good! Is there
| a way to keep it as system modal...that is make that
| progress bar run, and no other app. touchable until
| finished?

The original jumping was my fault (start time established in the wrong
place). Here's a cleaned up version of the IE box with a progress bar and
both count up/down of whole seconds, with the bar progress based on smaller
time increments, to get smoother bar progress.

With regard to system-modal: IE boxes should popup on top. In my
experience, this is true, even with Win2k/WinXp desktop foreground lock
settings, though there may be settings which negate this. There's no
inherent way to set an IE window as system modal.

Hiddensoft's freeware AutoItX (which is a great - and probably the most
often recommended - scripting add-on, if you can use a local ActiveX) added
a system-modal setting for any window in its early v3 beta, which I tested
and worked fine, but the v3 beta has now been pulled from its site until
release (hopefully soon). There may be another utility out there that will
do this, but I'm not aware of it. BTW, the AutoItX v3 beta also had the
capability to replace text inside a desktop window. I didn't play with that
method much, but it may be able to replace text inside a Popup,when it's
released.

http://www.hiddensoft.com/AutoIt/

---
nDisplayTime= 10
sMsg= "0 seconds elapsed - " _
& (nDisplayTime) & " seconds remaining"
nElapsedTime= 0
nLastTime= 0
nBarElapsedTime= 0
nBarLastTime= 0

nScrW= createobject( _
"htmlfile").parentWindow.screen.availWidth
nScrHt= createobject( _
"htmlfile").parentWindow.screen.availHeight

showBar oIe
wscript.sleep 50

oIe.document.parentWindow.document.script.barop 0
nStartTime= clng(timer)

do 'your operational loop

' ... (do something)
wscript.sleep 50 'demo substitute only

nBarElapsedTime= clng((timer- nStartTime) *100)
if (nBarElapsedTime<0) then


nStartTime= nStartTime -(60 *60 *24)

nBarElapsedTime= clng(timer- nStartTime)
end if

if (nBarElapsedTime>nBarLastTime) then
iPct= cint((nBarElapsedTime /(nDisplayTime *100)) *100)
nElapsedTime= clng(timer- nStartTime)
sMsg= nElapsedTime & " seconds elapsed - " _
& (nDisplayTime -nElapsedTime) _
& " seconds remaining"
nBarLastTime= nBarElapsedTime
nLastTime= nElapsedTime

loop until (nElapsedTime=nDisplayTime)

oIe.quit
wscript.quit

function showBar (oIe)

oIe.navigate("about:blank")

.height= 150

Joe Earnest

unread,
Feb 28, 2004, 1:27:34 PM2/28/04
to

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:4040D30B...@hydro.com...

|
| By the way, a very nice progress bar you have created there, Joe :-)
|

Thanks. ;-)

The last cleanup post above should be a smoother bar, along with the
1-second count-down count-up, and corrects my start-time goof that caused
the initial display jump.

If and when AutoItX v3 is released, the modal and replacement text issues
can be addressed through it.

Regards,
Joe

Joe Earnest

unread,
Feb 28, 2004, 1:52:28 PM2/28/04
to
Just when I thought that I had done this ...

Apparently the "midnight-check" on the timer can create problems when
performed on a hundreth-of-a-second basis. Throws some sporatic errors.
Performing it on whole seconds seems to be consistent. A very slightly
corrected version to address this:

---
nDisplayTime= 10
sMsg= "0 seconds elapsed - " _
& (nDisplayTime) & " seconds remaining"
nElapsedTime= 0
nLastTime= 0
nBarElapsedTime= 0
nBarLastTime= 0

nScrW= createobject( _
"htmlfile").parentWindow.screen.availWidth
nScrHt= createobject( _
"htmlfile").parentWindow.screen.availHeight

showBar oIe
wscript.sleep 50

oIe.document.parentWindow.document.script.barop 0
nStartTime= clng(timer)

do 'your operational loop

' ... (do something)
wscript.sleep 50 'demo substitute only

nBarElapsedTime= clng((timer- nStartTime) *100)
nElapsedTime= clng(timer- nStartTime)

if (nElapsedTime<0) then


nStartTime= nStartTime -(60 *60 *24)

nElapsedTime= clng(timer- nStartTime)


nBarElapsedTime= clng(timer- nStartTime)
end if

if (nBarElapsedTime>nBarLastTime) then
iPct= cint((nBarElapsedTime /(nDisplayTime *100)) *100)

loop until (nElapsedTime=nDisplayTime)

oIe.quit
wscript.quit

function showBar (oIe)

oIe.navigate("about:blank")

& "padding-right:7px;" _
& "text-align:left;" _

oIe.visible= true

end function
---

Joe

---

Torgeir Bakken (MVP)

unread,
Feb 28, 2004, 1:54:09 PM2/28/04
to
Joe Earnest wrote:

> "DE" wrote:
> > Guess I was wrong...The progress bar looks good! Is there
> > a way to keep it as system modal...that is make that
> > progress bar run, and no other app. touchable until
> > finished?
>

> (snip)


> With regard to system-modal: IE boxes should popup on top. In my
> experience, this is true, even with Win2k/WinXp desktop foreground lock
> settings, though there may be settings which negate this. There's no
> inherent way to set an IE window as system modal.

Hi

I would think using AppActivate inside the loop would give this effect
to a certain degree at least...

(and Joe, would you be very offended if I asked you to change | to > for
your newsreader's quote character? E.g. my newsreader doesn't recognize |
as a quote character, making it harder to read the posts)

DE

unread,
Feb 28, 2004, 2:59:47 PM2/28/04
to
Thanks guys!

>.
>

Joe Earnest

unread,
Feb 28, 2004, 3:17:34 PM2/28/04
to

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:4040E3D1...@hydro.com...

> Joe Earnest wrote:
> > (snip)
> > With regard to system-modal: IE boxes should popup on top. In my
> > experience, this is true, even with Win2k/WinXp desktop foreground lock
> > settings, though there may be settings which negate this. There's no
> > inherent way to set an IE window as system modal.
>
> Hi
>
> I would think using AppActivate inside the loop would give this effect
> to a certain degree at least...
>
> (and Joe, would you be very offended if I asked you to change | to > for
> your newsreader's quote character? E.g. my newsreader doesn't recognize |
> as a quote character, making it harder to read the posts)

Point 2 done. I was not aware of the issue with some newsreaders. I'm a
cheapie OE person, myself, so I just have the > | : selection for text
posts. ;-)

Point 1. Good point. I have AutoItX/AppActivate cranked into my library
functions for IeApp windows. But it never seems necessary when I test
posted scripts (mine or others), at least with Ie6 and WinXp. The IE
windows always seem to popup on top. If the foreground lock is an issue, in
my experience, AppActivate won't handle it (at least not without some real
gymnastics -- get and reset the registry value to 0, rundll the user
settings, run the IE window script segment, then reset the registy value and
rundll the user settings again), so AutoItX is necessary.

Regards,
Joe

Torgeir Bakken (MVP)

unread,
Feb 28, 2004, 3:33:04 PM2/28/04
to
Joe Earnest wrote:

> Torgeir Bakken (MVP) wrote:
> > Joe Earnest wrote:
> > > (snip)
> > > With regard to system-modal: IE boxes should popup on top. In my
> > > experience, this is true, even with Win2k/WinXp desktop foreground lock
> > > settings, though there may be settings which negate this. There's no
> > > inherent way to set an IE window as system modal.
> >

> > I would think using AppActivate inside the loop would give this effect
> > to a certain degree at least...
> >
> > (and Joe, would you be very offended if I asked you to change | to > for
> > your newsreader's quote character? E.g. my newsreader doesn't recognize |
> > as a quote character, making it harder to read the posts)
>
> Point 2 done. I was not aware of the issue with some newsreaders. I'm a
> cheapie OE person, myself, so I just have the > | : selection for text
> posts. ;-)

Thanks :-)


> Point 1. Good point. I have AutoItX/AppActivate cranked into my library
> functions for IeApp windows. But it never seems necessary when I test
> posted scripts (mine or others), at least with Ie6 and WinXp. The IE
> windows always seem to popup on top. If the foreground lock is an issue, in
> my experience, AppActivate won't handle it (at least not without some real
> gymnastics -- get and reset the registry value to 0, rundll the user
> settings, run the IE window script segment, then reset the registy value and
> rundll the user settings again), so AutoItX is necessary.

I see now that my AppActivate suggestion is based on my Win2k SP2
experience, where this works very well. Putting AppActivate into
the loop in your script will give the progress bar a foreground
lock appearance there.

But when running the same script with Win2k SP3/SP4 and WinXP, it
will only cause a rapid blinking of the IE entry in the task bar.
So, yes, as you say, for those OS versions, AppActivate is not an
option.

Dave Patrick

unread,
Feb 28, 2004, 1:01:41 PM2/28/04
to
Cool script but FYI on my Windows XP Pro SP-1 it always pops behind.

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft MVP [Windows]
Microsoft Certified Professional [Windows 2000]
http://www.microsoft.com/protect

Joe Earnest

unread,
Feb 28, 2004, 5:13:49 PM2/28/04
to
Hi,

"Dave Patrick" <ma...@NoSpam.DSPatrick.com> wrote in message
news:O0RtUOk$DHA....@TK2MSFTNGP11.phx.gbl...


> Cool script but FYI on my Windows XP Pro SP-1 it always pops behind.
>
> --
> Regards,
>
> Dave Patrick ....Please no email replies - reply in newsgroup.
> Microsoft MVP [Windows]
> Microsoft Certified Professional [Windows 2000]
> http://www.microsoft.com/protect

See the comments in the posts below from Torgeir Bakken and me. This is
contrary to my experience, but is likely the result of individual settings.
The most probable reason on WinXp is a forground lock setting. If so, the
following won't work, but try it anyway. Immediately after the window is
set as visible at the end of the function ("oIe.visible= true"), add the
following lines:

---
wscript.sleep 100
createobject("wscript.shell").appActivate "Progress Bar Demo"
---

If it works, great. If not, consider getting AutoItX (current version),
discussed in the post above. With it, the added lines would be:

---
wscript.sleep 100
createobject("autoItX.control").winActivate "Progress Bar Demo", ""

Dave Patrick

unread,
Feb 28, 2004, 5:21:27 PM2/28/04
to
Thanks Joe. It *did* work and FYI ForegroundLockTimeout is still set at
default of 200000 decimal.

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft MVP [Windows]
Microsoft Certified Professional [Windows 2000]
http://www.microsoft.com/protect


"Joe Earnest" wrote:
| Hi,

Torgeir Bakken (MVP)

unread,
Feb 28, 2004, 6:00:20 PM2/28/04
to
Dave Patrick wrote:

> Thanks Joe. It *did* work and FYI ForegroundLockTimeout is still set at
> default of 200000 decimal.

Hi

Ok, lets get that one into Google. Here is a modified version that has
put the title into the variable sTitle, and runs an appActivate on it
once after the dialog is up and running:


' Progress bar script using the IE object
'
' Author: Joe Earnest
' Appactivate code added 2004-02-28 by Torgeir Bakken
'

sTitle = "Progress Bar Demo"


nDisplayTime= 10
sMsg= "0 seconds elapsed - " _
& (nDisplayTime) & " seconds remaining"
nElapsedTime= 0
nLastTime= 0
nBarElapsedTime= 0
nBarLastTime= 0

nScrW= createobject( _
"htmlfile").parentWindow.screen.availWidth
nScrHt= createobject( _
"htmlfile").parentWindow.screen.availHeight

showBar oIe
wscript.sleep 50
createobject("wscript.shell").appActivate sTitle

oIe.document.parentWindow.document.script.barop 0
nStartTime= clng(timer)

do 'your operational loop

' ... (do something)
wscript.sleep 50 'demo substitute only

nBarElapsedTime= clng((timer- nStartTime) *100)
nElapsedTime= clng(timer- nStartTime)

if (nElapsedTime<0) then


nStartTime= nStartTime -(60 *60 *24)

nElapsedTime= clng(timer- nStartTime)


nBarElapsedTime= clng(timer- nStartTime)
end if

if (nBarElapsedTime>nBarLastTime) then
iPct= cint((nBarElapsedTime /(nDisplayTime *100)) *100)

oIe.quit
wscript.quit

function showBar (oIe)

oIe.navigate("about:blank")

.writeLn ("<title>" & sTitle & "</title>")


.writeLn ("<style type=""text/css"">")
.writeLn ("body {background-color:#ece9d8;" _
& "text-align:center;" _
& "vertical-align:middle}")
.writeLn ("</style>")
.writeLn ("<script language=""vbscript"">")
.writeLn ("function BarOp (vnPct)")
.writeln ("window.bar.style.width= vnPct & ""%""")
.writeLn ("end function")
.writeLn ("</script>")
.writeLn ("</head>")
.writeLn ("<body scroll=""no"">")
.writeLn ("<table>")
.writeLn ("<tr>")
.writeLn ("<td style=""text-align:center;" _
& "font-family:Arial;font-size:16pt;" _
& "font-weight:bold"">")
.writeLn ("Progress Bar Demo")
.writeLn ("</td>")
.writeLn ("</tr>")
.writeLn ("<tr>")
.writeLn ("<td id=""barcell"" " _
& "style=""width:400px;" _
& "padding-left:7px;" _

& "padding-right:7px;" _
& "text-align:left;" _

oIe.visible= true

end function

--

Dave Patrick

unread,
Feb 28, 2004, 6:12:54 PM2/28/04
to
Hi Torgeir,

And that initially is on top as well. I didn't mention in both cases the
wscript.echo "Script is complete."
does pop up behind though.

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft MVP [Windows]
Microsoft Certified Professional [Windows 2000]
http://www.microsoft.com/protect

Torgeir Bakken (MVP)

unread,
Feb 28, 2004, 6:20:30 PM2/28/04
to
Dave Patrick wrote:

> Hi Torgeir,
>
> And that initially is on top as well. I didn't mention in both cases the
> wscript.echo "Script is complete."
> does pop up behind though.

Hi

That one is simple to fix, replace

wscript.echo "Script is complete."

with

MsgBox "Script is complete.", vbSystemModal, sTitle

Dave Patrick

unread,
Feb 28, 2004, 6:30:07 PM2/28/04
to
Ahh yes. Thanks Torgeir

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft MVP [Windows]
Microsoft Certified Professional [Windows 2000]
http://www.microsoft.com/protect

Joe Earnest

unread,
Feb 28, 2004, 9:12:02 PM2/28/04
to
Hi,

"Dave Patrick" <ma...@NoSpam.DSPatrick.com> wrote in message

news:eOjWbzk$DHA....@TK2MSFTNGP10.phx.gbl...


> Thanks Joe. It *did* work and FYI ForegroundLockTimeout is still set at
> default of 200000 decimal.
>
> --
> Regards,
>
> Dave Patrick ....Please no email replies - reply in newsgroup.
> Microsoft MVP [Windows]
> Microsoft Certified Professional [Windows 2000]
> http://www.microsoft.com/protect

Good. It shouldn't -- but good. I suggested you try it, because
AppActivate's performance can be downright peculiar. It seems somehow to
behave better with IE windows than other window types. AppActivate reminds
me of slapping the side of your computer when it isn't working right --
sometimes that fixes it. I still recommend considering the AutoItX
alternative, if you can use a third-party ActiveX, for more consistent
behavior. The *most* peculiar window, in my experience, is the
BrowseForFolder window. I don't know what sets it apart, but trying to
activate it can -- irregularly -- set it as hidden (and I have to dismiss it
through Task Manager). And AppActivate doesn't seem to like some title
characters. For example, it will consistently activate a "WordPerfect 10"
window with the title string segment "WordPerfec", but consistently fail
with the title string segment "WordPerfect". Just downright strange.

Regards,

Joe Earnest

unread,
Feb 29, 2004, 2:12:54 PM2/29/04
to
Hi Torgeir,

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message

news:40411D84...@hydro.com...
[snip]


> Ok, lets get that one into Google. Here is a modified version that has
> put the title into the variable sTitle, and runs an appActivate on it
> once after the dialog is up and running:

I always worry when you "Google" my air code, because it's usually
unfinished and still has issues. ;-)

This post should be "Googlable". ;-)

It has the two progress bars from the thread, reformatted with message text
and split cells for the second bar, with minor corrections (some function
issues, and I changed the termination point so the second bar would actually
complete), with the needed suppression routines, etc., and duly noted and
credited. I also added a third, which is my favorite and the one I use the
most, which incorporates the scrolling filename technique that you posted.
I converted your example into a div under the progress bar.

----------

Here are three IE progress percentage-based bars that may be useful.

(1) The first is a simple percentage progress bar.

(2) The second incorporates time counters (elapsed and remaining), but could
easily be modified for file counters or whatever.

(3) The third is a file-processing progress bar, which incorporates a
scrolling list of file names. (The demo uses 40 file names from my WinXp
shell32 folder.)

All use kiosk style (reduced fullscreen with outset borders) to eliminate
the possibility of user dismissal through the titlebar or taskbar, and are
error-trapped in functions, so that they will automatically be regenerated,
if the user dismisses them by pressing Alt+F4. (Try pressing Alt+F4 during
the runs.) All three suppress all Ctrl key combinations, F1/F3/F5 (refresh)
combinations and the ContextMenu key (because of the refresh option), to
protect the window's integrity. All three use AppActivate to activate the
IE window, but have commented-out AutoItX activation lines as alternatives,
which is more reliable, if you have it.

Torgeir Bakken (MVP) supplied the activation suggestion in tweaking these
examples, with feedback from Dave Patrick (MVP). The scrolling file name
portion was taken from a complete window example posted by Torgeir Bakken,
and reformatted to be moved into a fixed div in a cell under the
progressbar. Torgeir credits the technique used to a suggestion in a post
by Michael Harris (MVP). The use of a "fat" <hr> tag as a percentage
progress bar occurred to me while reviewing the code for a different
percentage-based progress bar posted by Atrax. All of my IeApp window
techniques were developed initially from examples and sample script posted
on the microsoft.public.scripting.vbscript newsgroup by Tom Lavedas, Walter
Zachery, Torgeir Bakken, Michael Harris and Alex Angelopoulos (MVP), with
general HTML/DHTML technique learned from posts by Michael Harris, Gurgen
Alaverdian and Joe Fawcett (MVP). The refresh key/context menu suppression
script is loosely based on code posted by Thor Larholm on the
*.scripting.jscript newsgroup. Note that I use error-trapped polling loops
instead of GetRef + OnBeforeUnload techniques, largely because my library
methods are written into a WSC file, where the GetRef techique is
unavailable, but also because I find it to be more versatile.


-----
(1) Simple IE % Progress Bar
-----

sTitle= "Progress Bar Demo"

nScrW= createobject( _
"htmlfile").parentWindow.screen.availWidth
nScrHt= createobject( _
"htmlfile").parentWindow.screen.availHeight

showBar oIe, sTitle
wscript.sleep 50

oIe.document.parentWindow.document.script.barop 0

do 'your operational loop

' ... (do something)

iPct= iPct +1 'or your increment

on error resume next
oIe.document.parentWindow.document.script.barop iPct

if err then
err.clear
showBar oIe, sTitle
oIe.document.parentWindow.document.script.barop iPct


end if
on error goto 0

loop until (iPct=100)

wscript.sleep 1000
msgbox "Script is complete.", _
vbOkOnly +vbSystemModal, sTitle

oIe.quit
wscript.quit

function showBar (roIe, usTitle)

set roIe= createobject( _
"internetExplorer.application")

roIe.navigate("about:blank")

do
wscript.sleep 50
loop until roIe.readyState=4

with roIe


.fullScreen= true
.toolbar = false
.statusBar = false
.addressBar = false
.resizable= false
.width= 420
.height= 150
.left= (nScrW -420) \2

.top= (nScrHt -150) \2

with .document
.writeLn ("<!doctype html public>")
.writeLn ("<html style=""border-style:outset;" _

& "border-width:4px"" " _
& "onKeyDown=""vbscript:SuppressKeys"" " _
& "onHelp=""vbscript:SuppressIeFns"" " _
& "onContextMenu=""vbscript:SuppressIeFns"">")
.writeLn ("<head>")
.writeLn ("<title>" & usTitle & "</title>")


.writeLn ("<style type=""text/css"">")
.writeLn ("body {background-color:#ece9d8;" _
& "text-align:center;" _
& "vertical-align:middle}")
.writeLn ("</style>")
.writeLn ("<script language=""vbscript"">")

.writeLn ("function SuppressKeys ()")
.writeLn ("select case window.event.keyCode")
.writeLn ("case 112, 114, 116")
.writeLn ("case else: if NOT " _
& "cbool(window.event.ctrlKey) then " _
& "exit function")
.writeLn ("end select")
.writeLn ("window.event.keyCode= 0")
.writeLn ("window.event.cancelBubble= true")
.writeLn ("window.event.returnValue= false")


.writeLn ("end function")

.writeLn ("function SuppressIeFns ()")
.writeLn ("window.event.cancelBubble= true")
.writeLn ("window.event.returnValue= false")


.writeLn ("end function")

.writeLn ("function BarOp (unPct)")
.writeln ("window.bar.style.width= unPct & ""%""")

.writeLn ("<td style=""padding-top:20px;" _
& "width:400px;font-family:Arial;" _
& "font-size:10pt;" _
& "font-weight:bold"">")
.writeLn ("Loading files ...")


.writeLn ("</td>")
.writeLn ("</tr>")

.writeLn ("</table>")
.writeLn ("</body>")
.writeLn ("</html>")
end with

.visible= true
end with

wscript.sleep 100
createobject("wscript.shell").appActivate _
usTitle
'createobject("autoItX.control").winActivate _
' usTitle, ""

end function
-----


-----
(2) IE % Progress Bar with Time Counter
-----

sTitle= "Progress Bar Demo"

nDisplayTime= 10
sMsg= "0 seconds elapsed - " _
& (nDisplayTime) & " seconds remaining"
nElapsedTime= 0
nLastTime= 0
nBarElapsedTime= 0
nBarLastTime= 0

nScrW= createobject( _
"htmlfile").parentWindow.screen.availWidth
nScrHt= createobject( _
"htmlfile").parentWindow.screen.availHeight

showBarCounter oIe, sTitle, "0", cstr(nDisplayTime)
wscript.sleep 50

oIe.document.parentWindow.document.script.barop 0
nStartTime= clng(timer)

do 'your operational loop

' ... (do something)

nBarElapsedTime= clng((timer- nStartTime) *100)
nElapsedTime= clng(timer- nStartTime)
nRemainingTime= clng(nDisplayTime- nElapsedTime)

if (nElapsedTime<0) then
nStartTime= nStartTime -(60 *60 *24)
nElapsedTime= clng(timer- nStartTime)

nRemainingTime= clng(nDisplayTime- nElapsedTime)


nBarElapsedTime= clng(timer- nStartTime)
end if

if (nBarElapsedTime>nBarLastTime) then
iPct= cint((nBarElapsedTime /(nDisplayTime *100)) *100)

nBarLastTime= nBarElapsedTime
nLastTime= nElapsedTime

on error resume next
oIe.document.parentWindow.document.script.barop iPct

if (err=0) then _
oIe.document.all.elapsed.innerText= _
cstr(nElapsedTime) & " seconds elapsed"
if (err=0) then _
oIe.document.all.remaining.innerText= _
cstr(nRemainingTime) & " seconds remaining"

if err then
err.clear
showBarCounter oIe, sTitle, cstr(nElapsedTime), _
cstr(nRemainingTime)


oIe.document.parentWindow.document.script.barop iPct
oIe.document.all.msgcell.innerText= sMsg
end if
end if
on error goto 0

loop until (iPct=100)

wscript.sleep 1000
msgbox "Script is complete.", _
vbOkOnly +vbSystemModal, sTitle

oIe.quit
wscript.quit

function showBarCounter (roIe, usTitle, _
usElapsedTime, usRemainingTime)

set roIe= createobject( _
"internetExplorer.application")

roIe.navigate("about:blank")

do
wscript.sleep 50
loop until roIe.readyState=4

with roIe


.fullScreen= true
.toolbar = false
.statusBar = false
.addressBar = false
.resizable= false
.width= 420

.height= 170
.left= (nScrW -420) \2
.top= (nScrHt -170) \2

with .document
.writeLn ("<!doctype html public>")
.writeLn ("<html style=""border-style:outset;" _

& "border-width:4px"" " _
& "onKeyDown=""vbscript:SuppressKeys"" " _
& "onHelp=""vbscript:SuppressIeFns"" " _
& "onContextMenu=""vbscript:SuppressIeFns"">")
.writeLn ("<head>")
.writeLn ("<title>" & usTitle & "</title>")


.writeLn ("<style type=""text/css"">")
.writeLn ("body {background-color:#ece9d8;" _
& "text-align:center;" _
& "vertical-align:middle}")
.writeLn ("</style>")
.writeLn ("<script language=""vbscript"">")

.writeLn ("function SuppressKeys ()")
.writeLn ("select case window.event.keyCode")
.writeLn ("case 112, 114, 116")
.writeLn ("case else: if NOT " _
& "cbool(window.event.ctrlKey) then " _
& "exit function")
.writeLn ("end select")
.writeLn ("window.event.keyCode= 0")
.writeLn ("window.event.cancelBubble= true")
.writeLn ("window.event.returnValue= false")


.writeLn ("end function")

.writeLn ("function SuppressIeFns ()")
.writeLn ("window.event.cancelBubble= true")
.writeLn ("window.event.returnValue= false")


.writeLn ("end function")

.writeLn ("function BarOp (unPct)")
.writeln ("window.bar.style.width= unPct & ""%""")


.writeLn ("end function")
.writeLn ("</script>")
.writeLn ("</head>")
.writeLn ("<body scroll=""no"">")
.writeLn ("<table>")
.writeLn ("<tr>")

.writeLn ("<td colspan=""3"" " _
& "style=""text-align:center;" _


& "font-family:Arial;font-size:16pt;" _
& "font-weight:bold"">")
.writeLn ("Progress Bar Demo")
.writeLn ("</td>")
.writeLn ("</tr>")
.writeLn ("<tr>")
.writeLn ("<td id=""barcell"" " _

& "colspan=""3"" " _


& "style=""width:400px;" _
& "padding-left:7px;" _
& "padding-right:7px;" _
& "text-align:left;" _
& "border-style:inset;" _
& "border-width:thin;" _
& "background-color:navajowhite"">")
.writeLn ("<hr id=""bar"" " _
& "style=""width:0%;height:15px;" _
& "color:darkblue"" />")
.writeLn ("</td>")
.writeLn ("</tr>")
.writeLn ("<tr>")

.writeLn ("<td id=""elapsed"" " _
& "style=""width:49%;" _


& "text-align:center;" _
& "font-family:Arial;font-size:12pt;" _
& "font-weight:bold;" _
& "border-style:inset;" _
& "border-width:thin"">")

.writeLn (usElapsedTime & " seconds elapsed")
.writeLn ("</td>")
.writeLn ("<td style=""width:2%"">")
.writeLn ("</td>")
.writeLn ("<td id=""remaining"" " _
& "style=""width:49%;" _


& "text-align:center;" _
& "font-family:Arial;font-size:12pt;" _
& "font-weight:bold;" _
& "border-style:inset;" _
& "border-width:thin"">")

.writeLn (usRemainingTime & " seconds remaining")


.writeLn ("</td>")
.writeLn ("</tr>")
.writeLn ("<tr>")

.writeLn ("<td colspan=""3"" " _
& "style=""padding-top:20px;" _
& "font-family:Arial;" _
& "font-size:10pt;" _
& "font-weight:bold"">")
.writeLn ("Processing ...")


.writeLn ("</td>")
.writeLn ("</tr>")

.writeLn ("</table>")
.writeLn ("</body>")
.writeLn ("</html>")
end with

.visible= true
end with

wscript.sleep 100
createobject("wscript.shell").appActivate _
usTitle
'createobject("autoItX.control").winActivate _
' usTitle, ""

end function
'-----

-----
(3) IE % Progress Bar with Scrolling File Names
-----

sTitle= "Progress Bar Demo"

' 40 demo file names
iFiles= 40
sPath= "D:\WINDOWS\system32\"
sFiles= array(, _
"services.exe", _
"activeds.dll", _
"wmpcd.dll", _
"console.dll", _
"autofmt.exe", _
"c_950.nls", _
"comcat.dll", _
"dcache.bin", _
"dmview.ocx", _
"dsuiext.dll", _
"fontview.exe", _
"iccvid.dll", _
"ipxwan.dll", _
"kbdsf.dll", _
"mcdsrv32.dll", _
"modemui.dll", _
"faxpatch.exe", _
"mtxclu.dll", _
"ntmarta.dll", _
"olesvr.dll", _
"pscript.sep", _
"rsh.exe", _
"sfc.exe", _
"mstinit.exe", _
"timedate.cpl", _
"vga.drv", _
"winntbbu.dll", _
"wzcdlg.dll", _
"oddbse32.dll", _
"C_28597.NLS", _
"kbdkyr.dll", _
"wuaueng.dll", _
"sndvol32.exe", _
"VBAEN32.OLB", _
"WindowsLogon.manifest", _
"dx3j.dll", _
"winmm.dll", _
"shsvis.dll", _
"mshtml.dll", _
"itss.dll")

nScrW= createobject( _
"htmlfile").parentWindow.screen.availWidth
nScrHt= createobject( _
"htmlfile").parentWindow.screen.availHeight

showBar oIe, sTitle
wscript.sleep 50

oIe.document.parentWindow.document.script.barop 0

for iFile= 1 to iFiles

' ... (file operation)
wscript.sleep 100 'demo dummy operation only

iPct= cint((iFile /iFiles) *100)
sInsert= sPath & sFiles(iFile) & "<br />"
sReset= sReset & sInsert

on error resume next
oIe.document.parentWindow.document.script.barop iPct

if (err=0) then _
oIe.document.parentWindow.document.script.listop sInsert

if err then
err.clear
showBar oIe, sTitle
oIe.document.parentWindow.document.script.barop iPct
oIe.document.parentWindow.document.script.listop sReset


end if
on error goto 0

next

wscript.sleep 1000
msgbox "Script is complete.", _
vbOkOnly +vbSystemModal, sTitle

oIe.quit
'wscript.quit

function showBar (roIe, usTitle)

set roIe= createobject( _
"internetExplorer.application")

roIe.navigate("about:blank")

do
wscript.sleep 50
loop until roIe.readyState=4

with roIe


.fullScreen= true
.toolbar = false
.statusBar = false
.addressBar = false
.resizable= false
.width= 420

.height= 270
.left= (nScrW -420) \2
.top= (nScrHt -270) \2

with .document
.writeLn ("<!doctype html public>")
.writeLn ("<html style=""border-style:outset;" _

& "border-width:4px"" " _
& "onKeyDown=""vbscript:SuppressKeys"" " _
& "onHelp=""vbscript:SuppressIeFns"" " _
& "onContextMenu=""vbscript:SuppressIeFns"">")
.writeLn ("<head>")
.writeLn ("<title>" & usTitle & "</title>")


.writeLn ("<style type=""text/css"">")
.writeLn ("body {background-color:#ece9d8;" _
& "text-align:center;" _
& "vertical-align:middle}")
.writeLn ("</style>")
.writeLn ("<script language=""vbscript"">")

.writeLn ("function SuppressKeys ()")
.writeLn ("select case window.event.keyCode")
.writeLn ("case 112, 114, 116")
.writeLn ("case else: if NOT " _
& "cbool(window.event.ctrlKey) then " _
& "exit function")
.writeLn ("end select")
.writeLn ("window.event.keyCode= 0")
.writeLn ("window.event.cancelBubble= true")
.writeLn ("window.event.returnValue= false")


.writeLn ("end function")

.writeLn ("function SuppressIeFns ()")
.writeLn ("window.event.cancelBubble= true")
.writeLn ("window.event.returnValue= false")


.writeLn ("end function")

.writeLn ("function BarOp (unPct)")
.writeln ("window.bar.style.width= unPct & ""%""")


.writeLn ("end function")

.writeLn ("function ListOp (usInsert)")
.writeln ("window.insertfile.insertAdjacentHtml " _
& """beforeBegin"", usInsert")
.writeln ("window.insertfile.scrollIntoView")

.writeLn ("<td style=""padding-top:15px"">")
.writeLn ("<div id=""progresslist"" " _
& "style=""height:100px;width:380px;" _
& "max-height:100%;max-width:100%;" _
& "padding-left:10px;text-align:left;" _
& "font-family:Arial;font-size:10pt;" _
& "font-weight:bold;border-style:inset;" _
& "border-width:thin;overflow:scroll"">")
.writeLn ("<span id=""insertfile""></span>")
.writeLn ("</div>")


.writeLn ("</td>")
.writeLn ("</tr>")
.writeLn ("<tr>")

.writeLn ("<td style=""padding-top:20px;" _
& "width:400px;font-family:Arial;" _
& "font-size:10pt;" _
& "font-weight:bold"">")
.writeLn ("Loading files ...")


.writeLn ("</td>")
.writeLn ("</tr>")

.writeLn ("</table>")
.writeLn ("</body>")
.writeLn ("</html>")
end with

.visible= true
end with

wscript.sleep 100
createobject("wscript.shell").appActivate _
usTitle
'createobject("autoItX.control").winActivate _
' usTitle, ""

end function

-----

Regards,

Torgeir Bakken (MVP)

unread,
Feb 29, 2004, 2:33:18 PM2/29/04
to
Joe Earnest wrote:

> Hi Torgeir,


>
> Torgeir Bakken (MVP) wrote:
> [snip]
> > Ok, lets get that one into Google. Here is a modified version that has
> > put the title into the variable sTitle, and runs an appActivate on it
> > once after the dialog is up and running:
>
> I always worry when you "Google" my air code, because it's usually
> unfinished and still has issues. ;-)
>
> This post should be "Googlable". ;-)
>
> It has the two progress bars from the thread, reformatted with message text
> and split cells for the second bar, with minor corrections (some function
> issues, and I changed the termination point so the second bar would actually
> complete), with the needed suppression routines, etc., and duly noted and
> credited. I also added a third, which is my favorite and the one I use the
> most, which incorporates the scrolling filename technique that you posted.
> I converted your example into a div under the progress bar.
>
> ----------
>
> Here are three IE progress percentage-based bars that may be useful.
>
> (1) The first is a simple percentage progress bar.
>
> (2) The second incorporates time counters (elapsed and remaining), but could
> easily be modified for file counters or whatever.
>
> (3) The third is a file-processing progress bar, which incorporates a
> scrolling list of file names. (The demo uses 40 file names from my WinXp
> shell32 folder.)

> [snip code for 3 very nice progress bars]

Hi

Outstandingly superb post and code! When someone later on is asking for
how to create a progress bar, this is definitively the post to point to.

Thanks :-)

Dave Patrick

unread,
Feb 29, 2004, 7:58:31 PM2/29/04
to
Very cool. Thanks Joe

--
Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft MVP [Windows]
Microsoft Certified Professional [Windows 2000]
http://www.microsoft.com/protect


"Joe Earnest" wrote:
| Hi Torgeir,

0 new messages