
Progress or something to let user know script is in progress (WSH, not HTML)
Quote:
> Thanks.
> Originally I tried the Popup - my problem is that the script is being
> applied in many sites with various execution times - it varies according
> bandwidth available - that it is difficult to calculate time to keep pop up
> active.
> DHTML solution you mentioned would work even if launched from a WSH ? If so,
> can you please send your code to me ?
Hi
Some examples of using IE from a VBScript (WSH) to create a progress "dialog":
Using ms Internet Explorer for Scripting Dialogs
http://home.att.net/~wshvbs/#UsingIEforDialogs
Newsgroups: microsoft.public.scripting.wsh
Date: 2003-02-20 03:01:10 PST
http://groups.google.com/groups?selm=uz6xz7M2CHA.1640%40TK2MSFTNGP10....
Subject: Showing progress of VB script execution.
Newsgroups: microsoft.public.scripting.vbscript
Date: 2002-07-25 23:29:21 PST
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=1dc201c234...
Here is an example on using IE to give the user status while the script is
progressing:
Set oIE = CreateObject("InternetExplorer.Application")
Set oShell = CreateObject("WScript.Shell")
sTitle = "Message dialog" ' used by AppActivate
With oIE
' .FullScreen = True with a resize will give a very
' "clean" window (kiosk mode).
' The only way for the user to close the window is using Alt+F4
' (or terminate iexplore.exe)
' Doesn't work very good with IE6 SP1 anymore
'.FullScreen = True
' Here is a workaround:
' For a more "normal" window with a title bar with close cross,
' disable the line line ".FullScreen = True" and enable the 4 lines
' below. The script will handle that the user closes the window
.AddressBar = False
.ToolBar = False
.StatusBar = False
.Resizable = False
.Navigate("about:blank")
Do Until .readyState = 4: wscript.sleep 100: Loop
With .document
With .ParentWindow
SWidth = .Screen.AvailWidth
SHeight = .Screen.AvailHeight
SWidthW = .Screen.AvailWidth * .25
SHeightW = .Screen.AvailHeight * .1
.resizeto SWidthW, SHeightW
.moveto (SWidth - SWidthW)/2, (SHeight - SHeightW)/2
End With
' Joe Earnest's "refresh" protection
.WriteLn ("<html>")
.WriteLn ("<head>")
' If concatenating VBScript, concatenate
' vbCr's or vbCrLf's after each line.
' This script is placed in the head by
' convention; it can be placed in the body.
.WriteLn ("<script language=""vbscript"">")
' NOTE: The following code uses a hidden value to
' avoid external pushbutton subs.
' GetRef references to external subs in the script
' may also be used for pushbuttons.
' A hidden value provides better [x] or [Alt]+[F4] error
' trapping for a dialog with pushbuttons only, where no
' other controls are being polled.
' While this routine parses an exit button id in a specific manner,
' the entire exit buttion id could be placed the value,
' a string value could be polled, and the button id could be parsed
' later for specific operation.
.WriteLn ("Sub ExitButton ()")
.WriteLn ("ExitButtonID= LCase(Trim(window.event.srcelement.id))")
.WriteLn ("If Left(ExitButtonID, 4)=""xbtn"" Then")
.WriteLn ("window.exitbtn.value= Mid(ExitButtonID, 5)")
.WriteLn ("End If")
.WriteLn ("End Sub")
' NOTE: The following code traps refresh and context
' menu keys to avoid dialog corruption by refreshing.
.WriteLn ("Sub NoRefreshKey ()")
.WriteLn ("Select Case window.event.keycode")
.WriteLn ("Case 82: SuppressKey= window.event.ctrlkey")
.WriteLn ("Case 116: SuppressKey= True")
.WriteLn ("End Select")
.WriteLn ("If SuppressKey Then")
.WriteLn ("window.event.keycode= 0")
.WriteLn ("window.event.cancelbubble= True")
.WriteLn ("window.event.returnvalue= False")
.WriteLn ("End If")
.WriteLn ("End Sub")
.WriteLn ("Sub NoContextMenu ()")
.WriteLn ("window.event.cancelbubble= True")
.WriteLn ("window.event.returnvalue= False")
.WriteLn ("End Sub")
' NOTE: The following code implements the above subroutines.
.WriteLn ("Set document.onclick= GetRef(""ExitButton"")")
.WriteLn ("Set document.onkeydown= GetRef(""NoRefreshKey"")")
.WriteLn ("Set document.oncontextmenu= GetRef(""NoContextMenu"")")
.WriteLn ("</script>")
.WriteLn ("</head>")
.WriteLn ("<body>")
.WriteLn ("Script is Executing....")
.WriteLn ("</body>")
.WriteLn ("</html>")
With .ParentWindow.document.body
.style.backgroundcolor = "LightBlue"
.scroll="no"
.style.Font = "12pt 'Arial'"
'.style.borderStyle = "outset"
'.style.borderWidth = "2px"
End With
.Title = sTitle
oIE.Visible = True
WScript.Sleep 100
oShell.AppActivate sTitle
End With ' document
End With ' oIE
For i = 1 to 3
wscript.sleep 1500
MsgIE("Doing someting!" & vbCrLf & "New line # " & i)
Next
wscript.sleep 2000
MsgIE(" Script Complete!")
wscript.sleep 2000
MsgIE("IE_Quit")
Sub MsgIE(sMsg)
On Error Resume Next ' Just in case the IE window is closed
If sMsg = "IE_Quit" Then
oIE.Quit
Else
oIE.Document.Body.InnerText = sMsg
oShell.AppActivate sTitle
End If
End Sub
--
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