Progress or something to let user know script is in progress (WSH, not HTML) 
Author Message
 Progress or something to let user know script is in progress (WSH, not HTML)

I am running a script that calls another .exe (I am doing Shell..Run
"myapp", True, 2).

I would like to let users know that is something is going on so that my
users will not be tempted to reboot the machine or do something that could
interrupt the script execution.

I tried to adapt the script that is supposed to give us a progress in WSH,
but I am getting error "Object required:Status Window".

I don't necessarily need a progress bar - if you have an idea of how I can
let a message box sit there until my script comes to an end, please let me
know. Script execution time will vary from user to user (it depends on
bandwidth for respective site).

-----------------------------------------

' Get the maximum value of the progress bar
' GetMax will read this script for each line that has "AddToProgressBar" and
total the numbers. This is the quick and dirty way to get the max value for
the progress bar.

StatusWindow.Max = GetMax  '<==== *** Error here. Object
required:"StatusWindow"

' increment the progress bar by 3
AddToProgressBar 3

' insert code
' this code takes longer so we'll add a higher value to the progress bar

AddToProgressBar 12

Private Function GetMax()
    Const ForReading = 1, ForWriting = 2
    Dim fso, f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile(WScript.ScriptFullName, ForReading, True)
    strLine = f.ReadLine
    GetMax = 0
    While Not f.AtEndOfStream
        StartStr = InStr(1, strLine, "AddToProgressBar")
        If StartStr <> 0 Then
            num = Right(strLine, 2)
            If IsNumeric(num) Then
                GetMax = GetMax + num
            End If
        End If
        strLine = f.ReadLine
    Wend
End Function

Private Sub AddToProgressBar (value)
   Status.ProgressBarValue = Status.ProgressBarValue + value
End Sub



Mon, 15 Aug 2005 06:50:14 GMT  
 Progress or something to let user know script is in progress (WSH, not HTML)
If the users are executing this code from a cmd prompt you can do something
much like the following useing the Exec method rather than the Run Method

dim wshShell
dim Command
CONST IsRunning = 1

set wshShel = CreateObject("wscript.shell")

set Command = wshShell.Exec(somecommand)
if isObject(Command) Then
    do while Command.Status = IsRunning
         wscript.stdout.write "*"
          wscript.sleep 1000 'sleep for a second
    loop
end if

Thanks

--
Jeromy Statia [MSFT]

This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> I am running a script that calls another .exe (I am doing Shell..Run
> "myapp", True, 2).

> I would like to let users know that is something is going on so that my
> users will not be tempted to reboot the machine or do something that could
> interrupt the script execution.

> I tried to adapt the script that is supposed to give us a progress in WSH,
> but I am getting error "Object required:Status Window".

> I don't necessarily need a progress bar - if you have an idea of how I can
> let a message box sit there until my script comes to an end, please let me
> know. Script execution time will vary from user to user (it depends on
> bandwidth for respective site).

> -----------------------------------------

> ' Get the maximum value of the progress bar
> ' GetMax will read this script for each line that has "AddToProgressBar"
and
> total the numbers. This is the quick and dirty way to get the max value
for
> the progress bar.

> StatusWindow.Max = GetMax  '<==== *** Error here. Object
> required:"StatusWindow"

> ' increment the progress bar by 3
> AddToProgressBar 3

> ' insert code
> ' this code takes longer so we'll add a higher value to the progress bar

> AddToProgressBar 12

> Private Function GetMax()
>     Const ForReading = 1, ForWriting = 2
>     Dim fso, f
>     Set fso = CreateObject("Scripting.FileSystemObject")
>     Set f = fso.OpenTextFile(WScript.ScriptFullName, ForReading, True)
>     strLine = f.ReadLine
>     GetMax = 0
>     While Not f.AtEndOfStream
>         StartStr = InStr(1, strLine, "AddToProgressBar")
>         If StartStr <> 0 Then
>             num = Right(strLine, 2)
>             If IsNumeric(num) Then
>                 GetMax = GetMax + num
>             End If
>         End If
>         strLine = f.ReadLine
>     Wend
> End Function

> Private Sub AddToProgressBar (value)
>    Status.ProgressBarValue = Status.ProgressBarValue + value
> End Sub



Mon, 15 Aug 2005 11:55:51 GMT  
 Progress or something to let user know script is in progress (WSH, not HTML)
Hi,

Please note that any popup can be dismissed by the user by clicking [x] or
with Alt+F4.

If you have an older OS (at least pre-XP and maybe pre-2k, I can't recall
right now) you can popup a modeless keyless message box.  Unfortunately,
this ability went away in later OS's.

CreateObject("WScript.Shell").Popup("message",, "title", 75)

If you know approximately how long the process takes, you can use a popup
with a timer and a single Ok button, but its modal, so you'd need to run it
from a spin-off script (i.e., write and run without waiting a secondary
script with the command in it).

CreateObject("WScript.Shell").Popup("message", timer, "title", 64)

These are the easiest ways.  Otherwise, you can write an
InternetExplorer.Application DHTML window dialog.  I've posted
DialogDemo7temp.vbs previously, which has one form of a progress bar.  If
you want a copy, post back or email me, and I'll email it to you.  A number
of other examples have been posted.  Do a search of the newsgroup for
"progressbar" or "progress bar" on Google:

(watch for url wrap)
http://www.google.com/advanced_group_search?as_ugroup=microsoft.publi...
ting.*

Joe Earnest


Quote:
> I am running a script that calls another .exe (I am doing Shell..Run
> "myapp", True, 2).

> I would like to let users know that is something is going on so that my
> users will not be tempted to reboot the machine or do something that could
> interrupt the script execution.

> I tried to adapt the script that is supposed to give us a progress in WSH,
> but I am getting error "Object required:Status Window".

> I don't necessarily need a progress bar - if you have an idea of how I can
> let a message box sit there until my script comes to an end, please let me
> know. Script execution time will vary from user to user (it depends on
> bandwidth for respective site).

> -----------------------------------------

> ' Get the maximum value of the progress bar
> ' GetMax will read this script for each line that has "AddToProgressBar"
and
> total the numbers. This is the quick and dirty way to get the max value
for
> the progress bar.

> StatusWindow.Max = GetMax  '<==== *** Error here. Object
> required:"StatusWindow"

> ' increment the progress bar by 3
> AddToProgressBar 3

> ' insert code
> ' this code takes longer so we'll add a higher value to the progress bar

> AddToProgressBar 12

> Private Function GetMax()
>     Const ForReading = 1, ForWriting = 2
>     Dim fso, f
>     Set fso = CreateObject("Scripting.FileSystemObject")
>     Set f = fso.OpenTextFile(WScript.ScriptFullName, ForReading, True)
>     strLine = f.ReadLine
>     GetMax = 0
>     While Not f.AtEndOfStream
>         StartStr = InStr(1, strLine, "AddToProgressBar")
>         If StartStr <> 0 Then
>             num = Right(strLine, 2)
>             If IsNumeric(num) Then
>                 GetMax = GetMax + num
>             End If
>         End If
>         strLine = f.ReadLine
>     Wend
> End Function

> Private Sub AddToProgressBar (value)
>    Status.ProgressBarValue = Status.ProgressBarValue + value
> End Sub



Tue, 16 Aug 2005 00:33:43 GMT  
 Progress or something to let user know script is in progress (WSH, not HTML)
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 ?
Environment is XP & Win2K Prof IE5.5SP2 and later.


Quote:
> Hi,

> Please note that any popup can be dismissed by the user by clicking [x] or
> with Alt+F4.

> If you have an older OS (at least pre-XP and maybe pre-2k, I can't recall
> right now) you can popup a modeless keyless message box.  Unfortunately,
> this ability went away in later OS's.

> CreateObject("WScript.Shell").Popup("message",, "title", 75)

> If you know approximately how long the process takes, you can use a popup
> with a timer and a single Ok button, but its modal, so you'd need to run
it
> from a spin-off script (i.e., write and run without waiting a secondary
> script with the command in it).

> CreateObject("WScript.Shell").Popup("message", timer, "title", 64)

> These are the easiest ways.  Otherwise, you can write an
> InternetExplorer.Application DHTML window dialog.  I've posted
> DialogDemo7temp.vbs previously, which has one form of a progress bar.  If
> you want a copy, post back or email me, and I'll email it to you.  A
number
> of other examples have been posted.  Do a search of the newsgroup for
> "progressbar" or "progress bar" on Google:

> (watch for url wrap)

http://www.google.com/advanced_group_search?as_ugroup=microsoft.publi...

- Show quoted text -

Quote:
> ting.*

> Joe Earnest



> > I am running a script that calls another .exe (I am doing Shell..Run
> > "myapp", True, 2).

> > I would like to let users know that is something is going on so that my
> > users will not be tempted to reboot the machine or do something that
could
> > interrupt the script execution.

> > I tried to adapt the script that is supposed to give us a progress in
WSH,
> > but I am getting error "Object required:Status Window".

> > I don't necessarily need a progress bar - if you have an idea of how I
can
> > let a message box sit there until my script comes to an end, please let
me
> > know. Script execution time will vary from user to user (it depends on
> > bandwidth for respective site).

> > -----------------------------------------

> > ' Get the maximum value of the progress bar
> > ' GetMax will read this script for each line that has "AddToProgressBar"
> and
> > total the numbers. This is the quick and dirty way to get the max value
> for
> > the progress bar.

> > StatusWindow.Max = GetMax  '<==== *** Error here. Object
> > required:"StatusWindow"

> > ' increment the progress bar by 3
> > AddToProgressBar 3

> > ' insert code
> > ' this code takes longer so we'll add a higher value to the progress bar

> > AddToProgressBar 12

> > Private Function GetMax()
> >     Const ForReading = 1, ForWriting = 2
> >     Dim fso, f
> >     Set fso = CreateObject("Scripting.FileSystemObject")
> >     Set f = fso.OpenTextFile(WScript.ScriptFullName, ForReading, True)
> >     strLine = f.ReadLine
> >     GetMax = 0
> >     While Not f.AtEndOfStream
> >         StartStr = InStr(1, strLine, "AddToProgressBar")
> >         If StartStr <> 0 Then
> >             num = Right(strLine, 2)
> >             If IsNumeric(num) Then
> >                 GetMax = GetMax + num
> >             End If
> >         End If
> >         strLine = f.ReadLine
> >     Wend
> > End Function

> > Private Sub AddToProgressBar (value)
> >    Status.ProgressBarValue = Status.ProgressBarValue + value
> > End Sub



Tue, 16 Aug 2005 03:18:26 GMT  
 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



Tue, 16 Aug 2005 03:39:38 GMT  
 Progress or something to let user know script is in progress (WSH, not HTML)
Hi


Quote:
> DHTML solution you mentioned would work even if launched from a WSH ? If
so,
> can you please send your code to me ?
> Environment is XP & Win2K Prof IE5.5SP2 and later.

Torgeir's post may have taken care of your needs.  I tried to email you the
code, but it was rejected.  If you still want the code, please email me with
a returnable address.

Joe Earnest



Tue, 16 Aug 2005 08:37:15 GMT  
 Progress or something to let user know script is in progress (WSH, not HTML)
Thanks, big guys. I've got it working on my machine.

When I deploy this on a large number of Win2KIE5.5, I need to register the
.wsc component of my script right before running the script, right ?


Quote:
> Hi



> > DHTML solution you mentioned would work even if launched from a WSH ? If
> so,
> > can you please send your code to me ?
> > Environment is XP & Win2K Prof IE5.5SP2 and later.

> Torgeir's post may have taken care of your needs.  I tried to email you
the
> code, but it was rejected.  If you still want the code, please email me
with
> a returnable address.

> Joe Earnest



Tue, 16 Aug 2005 14:00:13 GMT  
 Progress or something to let user know script is in progress (WSH, not HTML)

Quote:

> Thanks, big guys. I've got it working on my machine.

> When I deploy this on a large number of Win2KIE5.5, I need to
> register the .wsc component of my script right before running the
> script, right ?

WSCs don't need to be registered or even have a <registration> element to be
accessible...

set obj = getobject("script:<component_path><#component_id>")

where:

<component_path> can be:
    c:\mypath\mywsc.wsc
    \\server\share\mypath\mywsc.wsc
    http://server/mysite/mypath/mywsc.wsc

<#component_id> is optional.  You get the 1st component in the WSC by
default.  You only need #component_id if there is more than one in the WSC
and you want one other than the first...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Technet Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp



Wed, 17 Aug 2005 09:55:05 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Let know user about script status

2. Progress Bar in WSH Scripting...

3. File Loading Progress Form with Progress Bar

4. How do I display a progress bar showing progress for database replication

5. How do I display a progress bar showing progress for database replication

6. Progress bar measuring FileCopy progress

7. Want a Progress/Info window but not MSGBOX

8. Not running, am I doing something wrong

9. How do I let the user save something?

10. Create a Progress/Info Window in WSH?

11. ann: a wsh Lite Weight Progress Dialog Offer

12. Progress Bar in WSH

 

 
Powered by phpBB® Forum Software