Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding some kind of progress notification to a script. 6

Status
Not open for further replies.

MISMCSA

MIS
Jun 24, 2004
43
0
0
US
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.
 
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!
 
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: ' 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
 
And one from me as well...

[red]"... 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[/red]
 
Just got a chance to look at this now and it was really helpful. Works perfect.

STAR
 
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
 
Congrants Mark

Really simple and truly brilliant solution.

--- McMerfy
 
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........
 
Cool, thanks for sharing.

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

Regards,

Mark
 
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.
 
'***************************************************
'* 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'
 
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
 
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
 
How about adding an On Error Resume Next?

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

Regards,

Mark
 
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?
 
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
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top