×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Adding some kind of progress notification to a script.
6

Adding some kind of progress notification to a script.

Adding some kind of progress notification to a script.

(OP)
Are there any methods that will allow me to add progress notification during the running of a script.

For example, I have a script that mirrors some data and can take about 1 - 2 minutes.  Right now you run the script, it looks like nothing is happening, and then a messagebox pops up at the end saying it's done.  Is it possible for me to code something that will show a message box, or something like that, saying the updating is taken place?

Thanks for help/suggestions.

RE: Adding some kind of progress notification to a script.

If you do a Keyword Search in this forum for 'progress' or 'progress bar' or 'progress indicator' you'll probably find many solutions.

HTH.

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr!  It's driving me nuts!"

RE: Adding some kind of progress notification to a script.

6
I think you will like this.  You should be able to work the test condition into your script to get this to eventually stop running.  As is this will go forever.  Note, this isn't  atrue progress bar but it let's the user know that something is going on.

[script]
'==========================================================================
'
' NAME: DisplayProgressBar.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: http://www.thespidersparlor.com
' DATE  : 8/11/2004
'
' COMMENT: <comment>
'
'==========================================================================

TestCondition = ""
stage = 1
Do
   If stage > 0 Then
           stage = DisplayProgress(stage)
   End If
Loop While TestCondition = ""



Function DisplayProgress(stage)
'Here is a phony progress bar that uses an IE Window
set x = createobject("internetexplorer.application")
'in code, the colon acts as a line feed
x.navigate2 "about:blank" : x.width = 350 : x.height = 80 : x.toolbar = false : x.menubar = false : x.statusbar = false : x.visible = True

x.document.write "<font color=blue>"
For n = 1 to 100
    x.document.write "|"
    wscript.sleep 50
    x.document.title = "Stage " & stage & " " & n & " %"
Next
stage = stage + 1
'close the window
x.quit
set x = nothing
DisplayProgress = stage

End Function

[/script]

I hope you find this post helpful.  Please let me know if it was.

Regards,

Mark

RE: Adding some kind of progress notification to a script.

Mark, excellent - have a star.

RE: Adding some kind of progress notification to a script.

....and another star, fantastic idea!

RE: Adding some kind of progress notification to a script.

And one from me as well...

"... isn't sanity really just a one trick pony anyway?!  I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick

RE: Adding some kind of progress notification to a script.

(OP)
Just got a chance to look at this now and it was really helpful.  Works perfect.

STAR

RE: Adding some kind of progress notification to a script.

MISMCSA, how about posting code on how you used it.  I am always interested in seeing how others adapt my code.  

I hope you find this post helpful.  Please let me know if it was.

Regards,

Mark

RE: Adding some kind of progress notification to a script.

Congrants Mark

Really simple and truly brilliant solution.

--- McMerfy

RE: Adding some kind of progress notification to a script.

Mark

I have a script that creates new user accounts but before it does so it searches through 7 containers to make sure that the user name is not already in use, up until now the user just sat there unaware of what was going on but as you can see in the following excerpt I have used the progress bar to let the user know that something is actually being done:

firstname=inputbox("Type the users first name")
    if firstname =""then
    wscript.echo "You didn't enter a recognised name"
    wscript.quit
    end if
    lastname1=inputbox("Type the users surname")
     if lastname1 =""then
     wscript.echo "You didn't enter a recognised surname"
     wscript.quit
     end if
     lastname= UCase(lastname1)
      initial = LCase(Left(firstName, 1))
       initial2 = LCase(Left(firstName, 2))
        username1 = LCase(left(lastName,6))    
         username = username1 & initial
          bothName = firstName & " " & lastName    
           strdisplayname = lastname & " " & firstname & " -my company domain"
            strdisplayname1 = lastname & ", " & firstname & " -my company domain"

set objExplorer = createobject("internetexplorer.application")

objExplorer.navigate2 "about:blank" : objExplorer.width = 350 : objExplorer.height = 120 : objExplorer.toolbar = false : objExplorer.menubar = false : objExplorer.statusbar = false : objExplorer.visible = True

objExplorer.document.write "<font color=green>"
objExplorer.document.write "<MARQUEE WIDTH=100% BEHAVIOR=ALTERNATE>Creating user account!</MARQUEE><br>"
    objExplorer.document.title = "Please be patient.... "
    objExplorer.document.write "<font color=red>"


dim strnames(7)
strnames(0)="OU= Site1 ,OU=XP Users,OU=City1,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(1)="OU= Site4,OU=XP Users,OU=City1,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(2)="OU= Site3,OU=XP Users,OU=City1,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(3)="OU= Site2,OU=XP Users,OU=City1,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(4)="OU= XP Users,OU=City1,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(5)="OU= Users,OU=City1,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(6)="OU= XP Users,OU=City5,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"
strnames(7)="OU= Users,OU=City5,OU=Sites,DC=domain,DC=intra,DC=my company,DC=com"

for i= 0 to 7
Set objDomain = GetObject("LDAP://" & strnames(i))
   For Each objUser In objDomain
   If UCase(objUser.sAMAccountName) = UCase(username) Then
   initial  = LCase(Left(firstName, 2))
   username1 = LCase(left(lastName,6))    
         username = username1 & initial
  Exit For
 End If
Next

For n = 1 to 10
    objExplorer.document.write "|"
    wscript.sleep 10
Next

next
 
  set objParent = GetObject("LDAP://" & strldap)
  set objUser   = objParent.Create("user", "cn=" & strdisplayname)
  
  objUser.Put "sAMAccountName", "" & username  
   objUser.Put "userPrincipalName", "" & username & "@domain.intra.my company.com"
   objUser.Put "givenName", "" & firstname
    objUser.Put "sn", "" & lastname1
     objUser.Put "displayName", "" & strdisplayname1
      objuser.Put "physicalDeliveryOfficeName", "" & stroffice
       objuser.Put "Description" ,"New user: " & Date
        objuser.Put "scriptPath", "pilot.syn"
         objUser.TerminalServicesProfilePath  = "\\" & strfshare & "\profiles.$\" & username & "\terminal"
          objUser.mail = firstname & "." & lastname1 & "@my company.com"
            objUser.SetInfo
             objUser.SetPassword "password"
              objUser.AccountDisabled = TRUE
               objuser.setinfo


objExplorer.Navigate "about:blank"  
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 400
objExplorer.Height = 240
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.document.write "*-*-*-*-*-*New XP User script*-*-*-*-*-*<p>Account created as: <font color=green>" & username &_
"</font><br>Terminal Services Path:<br><font color=green> " & "\\" & strfshare & "\profiles.$\" & username &_
"\terminal </font><br>Login Script:<font color=green> pilot.syn</font><br>Building: <font color=green>"& strbuild &_
"</font><br>Full Username: <font color=green>" & strdisplayname1 &"</font>"
objExplorer.document.title = "User has now been created..."
wscript.sleep 10000
objexplorer.Quit



etc........

RE: Adding some kind of progress notification to a script.

Cool, thanks for sharing.

I hope you find this post helpful.  Please let me know if it was.

Regards,

Mark

RE: Adding some kind of progress notification to a script.

Here is what we do for ours:

CODE

Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
objExplorer.Navigate "Colonial Place Logon Script"   
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width=400
objExplorer.Height = 150
objExplorer.Left = 0
objExplorer.Top = 0
Do While (objExplorer.Busy)
    Wscript.Sleep 200
Loop    
objExplorer.Visible = 1             
objExplorer.Document.Body.InnerHTML = "Starting the Colonial Place logon script. " _
    & "Please don't close this window as it will update you with what the script is currently " _
    & "doing to your computer."
    Wscript.Sleep 9000

objExplorer.Document.Body.InnerHTML = "Setting password protected screen saver for your system."
Wscript.Sleep 2000

objExplorer.Document.Body.InnerHTML = "Mapping network drives on your system."
Wscript.Sleep 2000


objExplorer.Document.Body.InnerHTML = "Installing network printers on your system."
Wscript.Sleep 2000

Of course we do have the functionality of the script in between, but didn't want to bore anyone with that simple portion of scripting.

RE: Adding some kind of progress notification to a script.

'***************************************************
'*    Script for deleting old computer accounts    *
'*       Written by : David J. 9/9/2004            *
'* \\*****\*******\Scripts\ADDeletions\DelComp.vbs*
'*      Relies on NetPWAge.exe by Marty List       *
'*     Cool Progress bar by Mark D. MacLachlan     *
'*   Line remed out that actually deletes 9/10/4   *
'***************************************************

'***************************************************
'*          Get Variables from User                *
'***************************************************
Dom = InputBox("Domain to delete computers in?", "Domain Query")
Age = InputBox("Delete Computers not used for how many days?", "Age Query")
count = -1
stage = 1

'***************************************************
'*    Use NetPWAge to Generate worklist            *
'***************************************************
Set objShell = CreateObject("WScript.Shell")
set running = objShell.exec ("%COMSPEC% /c netpwage /MACHINES /domain:" & Dom & " /min:" & Age & " /b /v>workfile.txt")
message = "Scanning " & Dom & " for computers that have not been accessed for " & Age & " days..."
Do While running.Status = 0
   If stage > 0 Then
           stage = DisplayProgress(stage)
   End If

Loop

'***************************************************
'*        Count computers and verify action        *
'***************************************************
Const ForReading = 1
Set objFSO2 = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO2.OpenTextFile(".\workfile.txt", ForReading)
Do While objTextFile.AtEndOfStream <> True
  strLinetoParse = objTextFile.ReadLine
  count = count + 1
Loop
Verify = InputBox("Really Delete " & Count & " Computers from " & dom & "?", "Verify this Action!!!! (Yes or No)")
If verify = "yes" then

'***************************************************
'*          Log file creation and header           *
'***************************************************
  Set objFSO1 = CreateObject ("Scripting.FileSystemObject")
  strOutputDir = "\\*****\********\Scripts\ADDeletions\Computers\"
  strYear = Year(Date)
  strMonth = Month(Date)
  strDay = Day(Date)
  strOutputFile = "DeletedComputers" & strYear & "-" & strMonth & "-" & strDay & ".txt"
  strFullName = strOutputDir & strOutputFile
  Set objFileRpt = objFSO1.CreateTextFile (strFullName, True)
  objFileRpt.writeline "Deleted Computer Report. Created " & now
  objFileRpt.writeline "Script Location: \\*****\********\Scripts\ADDeletions\DelComp.vbs"
  objFileRpt.writeBlankLines (1)
  objFileRpt.writeline ("******************************************************************************")
  objFileRpt.writeBlankLines (1)

'***************************************************
'*  Read Computer Name from each line in workfile  *
'***************************************************
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objTextFile = objFSO.OpenTextFile(".\workfile.txt", ForReading)
  Do While objTextFile.AtEndOfStream <> True
    strLinetoParse = objTextFile.ReadLine
    NameLength = Instr(strLinetoParse, " ") - 1
    If NameLength > 0 then
      Computer = Mid(strLinetoParse, 1, NameLength)
      DomainString = """" & Dom & """"
      compString = """" & Computer & """"

'***********************************************
'*         Connect to the Domain               *
'***********************************************
      Set DomainObj = GetObject("WinNT://" & DomainString)

'***********************************************
'*           Write Log File entry              *
'***********************************************
      objFileRpt.writeline "Deleted Computer " & Computer

'***********************************************
'*          Delete the Computer                *
'***********************************************
'      DomainObj.Delete "computer", CompString
    end if
  Loop

'***************************************************
'*                Log file Footer                  *
'***************************************************
  objFileRpt.writeBlankLines (1)
  objFileRpt.writeline "Deleted " & count & " Computers from " & Dom
  Wscript.echo "Deleted " & count & " Computers from " & Dom
  Wscript.Echo "Log file created - " & strFullName
Else
  Wscript.echo "Action Not verified!! - No computer accounts deleted from " & Dom
end if

'***************************************************
'*            Progress Bar Function                *
'***************************************************
Function DisplayProgress(stage)
Set objExplorer = Nothing
set objExplorer = createobject("internetexplorer.application")
objExplorer.navigate2 "about:blank" : objExplorer.width = 640 : objExplorer.height = 120 : objExplorer.toolbar = false : objExplorer.menubar = false : objExplorer.statusbar = false : objExplorer.visible = True
objExplorer.document.write "<font color=blue>"
objExplorer.document.write "<MARQUEE WIDTH=100% BEHAVIOR=ALTERNATE>" & Message & "</MARQUEE><br>"
    objExplorer.document.title = "Please be patient.... Performing Pass " & Stage
    objExplorer.document.write "<font color=red>"
For n = 1 to 195
    objExplorer.document.write "|"
    wscript.sleep 45
Next
stage = stage + 1
objExplorer.quit
DisplayProgress = stage
End Function


I was occasionally getting an error about an object disconnecting from the client untill I moved '= nothing' immediately prior to '= createObject'

RE: Adding some kind of progress notification to a script.

Thanks for sharing Jerz!

If you primarily run this in a single domain environment, you could have the script find the domain name, thus eliminating the need for one pop up.  You can do it like this:

Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")

Thanks for the honorable mention in your code.  It made me smile.  

I hope you find this post helpful.  Please let me know if it was.

Regards,

Mark

RE: Adding some kind of progress notification to a script.

Well, I thought moving that line fixed it, but I was wrong.

It will work 4 or 5 times all the way through the script, then for no apparent reason, I get:

Windows Script Host
Script: .......................\delcomp.vbs
Line:106
Char:1
Error:The Object invoked has disconnected from its clients.
Code:80010108
Source:(null)

Can anybody tell me how I can make it work everytime?
Thanks,
Jerz

RE: Adding some kind of progress notification to a script.

How about adding an On Error Resume Next?

I hope you find this post helpful.  Please let me know if it was.

Regards,

Mark

RE: Adding some kind of progress notification to a script.

Yes, thank you - on error resume next fixed the problem with it not running.

Now on to the next problem - your code for getting the domain name returns the LDAP name xxx.yyy.zzz.  The utility the script runs needs the old-school NT Domain name, AAAAAAAAAA.  I think it's in WinNT provider, and I can get a list of 'all' old school names with:

Set prov = GetObject("WinNT:")
For each dom in prov

How to make it return only the one the current server belongs to?

RE: Adding some kind of progress notification to a script.

TFG13

He has posted a great script as well and was able to get it working in my script. The only question i have.

How do you make sure that the explorer screen closes in the end of the script?

Hope someone can give me an answer

Patrick

RE: Adding some kind of progress notification to a script.

Hi Patrick,

If you created the object using this as an example:

CODE

Set objIE = CreateObject("InternetExplorer.Application")
Set objDoc = objIE.Document

Then you could shut the window using this:

CODE

objDoc.Close
objIE.Close

Spong

RE: Adding some kind of progress notification to a script.

patrick118,
This is all we do:

CODE

objExplorer.Document.Body.InnerHTML = "Logon script is now complete and you may close this window."
Wscript.Sleep 3000
Wscript.Quit

RE: Adding some kind of progress notification to a script.

yep. Got it. Working great now.

I love this scripting. Really helping me with stuff. Now got my script finished and replaced my kixstart script for the one i made.

Thank you all for helping

Patrick

RE: Adding some kind of progress notification to a script.

This version of Marks outstanding script gives the appearence of stepping through as it calls some other scripts.
Thanks to PHV for pointing me to Marks script which I found a week or two ago, but then could not find this thread again. Special thanks to Mark for coming up with such a cool way to track progress!!
If anybody can see a better way to do what I did with Mark's script below, please share.
Cheers!!



strComputer = "."

Set Shell = wscript.createobject("wscript.shell")
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")


stage = 1
   If stage > 0 Then
           stage = DisplayProgress(stage)
   End If
Wscript.sleep 250


Function DisplayProgress(stage)
set x = createobject("internetexplorer.application")
x.navigate2 "about:blank" : x.width = 350 : x.height = 95
x.toolbar = false : x.menubar = false : x.statusbar = false : x.visible = True

x.document.write "<font color=blue>"
x.document.write "<MARQUEE WIDTH=100% BEHAVIOR=ALTERNATE> Applying settings!</MARQUEE><br>"
    x.document.title = "Please be patient.... "
    x.document.write "<font color=blue>"

Wscript.sleep 100
For n = 1 to 25
    x.document.write "|"
    wscript.sleep 15
    x.document.title = "Stage " & stage & " " & n & " %"
Next

Wscript.sleep 2000
Shell.run "CALL\StpPrcs.vbs", TRUE

For n = 26 to 50
    x.document.write "|"
    wscript.sleep 10
    x.document.title = "Stage " & stage & " " & n & " %"
Next

Wscript.sleep 1500
Set objItem = objWMIService.Get("SystemRestore")
errResults = objItem.Disable("")

For n = 51 to 75
    x.document.write "|"
    wscript.sleep 10
    x.document.title = "Stage " & stage & " " & n & " %"
Next

Wscript.sleep 1500
Shell.run "CALL\DelRgVlu.vbs"

For n = 76 to 100
    x.document.write "|"
    wscript.sleep 10
    x.document.title = "Stage " & stage & " " & n & " %"
Next

Wscript.sleep 2000
Shell.run "CALL\Rbt.vbs"


stage = stage - 1
x.quit
set x = nothing
DisplayProgress = stage

End Function

RE: Adding some kind of progress notification to a script.

I also played with these scripts but i found another solution. I also made sure it opened an internet explorer window and then made sure it opened a flash file in it. This flah file was showing a bar that constantly moved from one side to another. Users in my network found it to be great and it looks really good. Even put music in it etc.

patrick

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close