We want to remove Office 2003.
Can someone help me with a VB script that shows a countdown before the processes winword.exe, excel.exe etc would be killed and Office 2003 uninstalled?
0 Comments   [ + ] Show Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.


Here's a reasonable progress bar script which uses IE as a container. It's one I obtained a while ago, meaning to customise it for my purposes but I switched to using HTAs so never got around to it. '-- This progress bar is a variation on #1 sample. It takes a different approach by
'-- writing a default bar web page during class initialization and sending the created IE
'-- instance to open that file. It writes default property values to the file, hard-coded
'-- into the class. You can then programmatically change the properties in script.
'-- Most properties can be changed anytime while the script is running, which allows
'-- for an updating caption and window re-use.

Dim bar, i
Dim intInitialUnits
Dim strInitialCaption

On Error Resume Next

intInitialUnits = 1500 'Change this value to change unit number
strInitialCaption = "When the bar completes, all Office apps will be forcibly closed!"

'-- create a class instance. --------
Set bar = new IEProgBar
'-- set some bar properties and run it. ----------
With bar
.Move -1, -1, 500, -1
.Units = intInitialUnits

'For i = 0 to (intInitialUnits - 1)
For i = 1 to intInitialUnits
WScript.Sleep 500
If i = 750 Then .Caption = "Halfway."
If i = 1350 Then .Caption = "Almost done."
End With

'-- second running of bar using the same instance/webpage.
'-- This resets the count and makes changes to appearance before running
'-- the bar again. Note that if you change BackColor it should be done before calling Reset
'-- because the Reset sub resets background color of the progress units to BackColor value.

With bar
.Background = ""
.Icon = "progicon.gif"
.BackColor = "FFDCA8"
.Reset '-- Reset should be called after BackColor is set because Reset will recolor progress units to back color value.
.TextColor = "4F009D"
.Title = "Second Version"
.Caption = "This demo shows more options."
.ProgressColor = "109494"
.Units = 20

.Move 400, 300, 350, 150
For i = 0 to 19
WScript.Sleep 500
If i = 8 Then .Caption = "A back picture can be used."
If i = 14 Then .Caption = "Most properties can be changed while running."
End With

Set bar = Nothing

'----- //////////////////////////////////////////////////////////////////////////////////////////////

' -- Progress bar Class that can be pasted into scripts.
'-- To create Progress bar: Dim ob
' Set ob = New IEProgBar

'-- This progress bar is created with an HTML file, which is written to the Temp folder
'-- and opened from there.

'-- Methods and Properties:

' Methods -

' Show - displays progress bar.
' Hide - hides the progress bar.
' Move(Left, Top, Width, Height) - moves and/or resizes window. All parameters must be used.
' Use -1 For any dimension Not being changed: ob.Move 10, 10, -1, -1
' default size is 400 W x 120 H. default position is Windows default.
' Advance - advances progress by 1 unit.
' Reset - Resets progress units to 0. Other properties are not changed. The dynamic properties
' can be changed just before or after Reset but Icon property cannot.
' CleanIETitle - removes Registry settings that append advertising to the page
' title in the IE title bar so that only the specified Title Property
' will be displayed. (This is a general change to IE and is Not reversible
' with this script as written.)

' Properties -
' Properties notes:
' 1) Properties marked "DYNAMIC" can be Reset at any time while progress bar is running.
' 2) Picture properties (Background and Icon) require a valid path. Progress bar page loads from
' TEMP folder. Background and Icon properties will copy the specified image file to TEMP so that IE can find it.
' It seems to work to just give FSO the file name If it's in the same folder where the script is running.
' If that does Not work For any reason Then the full path will be needed. The path should Not
' be like "file:///..." because the progess bar Class is using FSO to copy the file to TEMP and Then
' just giving IE the relative path as file name.
' Background - background picture. Use "" to remove. DYNAMIC.
' (Note: Class code copies picture to TEMP folder. Background parameter should
' be path of picture file. File name seems to work if in same folder as this script. )
' BackColor - 6-character hex code to specify background color. default is "E0E0E4". DYNAMIC.
' TextColor - 6-character hex code to specify caption text color. default is "000000". DYNAMIC.
' ProgressColor - 6-character hex code to specify progress color. default is "0000A0". DYNAMIC.
' Title - window title text. default is "Progress" DYNAMIC.
' Caption - text caption in window. default is "Progress. . ." DYNAMIC.
' Icon - path of any image file that can be used as an icon. (JPG, GIF, BMP or ICO)
' default is no icon. If an icon is specifed it appears to left of caption.
' NOTE: Webpage is created in TEMP folder so picture path must be Set accordingly.

' --- ( Units - number of progress units to use. Default is 20. This is not a public property. It MUST BE HARD CODED.
' before the webpage is created. Units is the value of ProgressUnits variable.)

'--- ////////////////////////////////////////////////////////////////////////////////////////

'-------- Start Progress bar Class ----------------------------------
Class IEProgBar
Private FSO, IE, BackCol, ProgressCol, ProgressUnits, Q2, sTemp, iProgress

Private Sub Class_Initialize()
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
sTemp = FSO.GetSpecialFolder(2)
Q2 = Chr(34)
Set IE = CreateObject("InternetExplorer.Application")

With IE
.AddressBar = False
.menubar = False
.ToolBar = False
.StatusBar = False
.width = 400
.height = 120
.resizable = True
.visible = False
End With

'-- set internal variable defaults. These variables are needed for Reset sub and Advance sub.
BackCol = "E0E0E4" '--background color.
ProgressCol = "0000A0" '--progress color.
ProgressUnits = intInitialUnits 'number of progress units.
iProgress = 0 '--to track progress.

'--writes webpage and loads it:
Do Until IE.ReadyState = 4
End Sub

Private Sub Class_Terminate()
On Error Resume Next
WScript.DisconnectObject IE
Set IE = Nothing
Set FSO = Nothing
End Sub

Public Sub Show()
IE.Visible = True
End Sub

Public Sub Hide()
IE.Visible = False
End Sub

'-- Advance method colors one progress unit. iProgress variable tracks how many
'-- units have been colored. Each progress unit is a <TD> with ID="P". They can be
'-- accessed in sequence through Document.All.Item.

Public Sub Advance()
On Error Resume Next
If (iProgress < ProgressUnits) and (IE.Visible = True) Then
IE.Document.parentWindow.Prog1(iProgress).bgcolor = ProgressCol
iProgress = iProgress + 1
End If
End Sub

'------ Reset progress for another use. --------------------------------
Public Sub Reset()
Dim i2
On Error Resume Next
For i2 = 0 to (ProgressUnits - 1)
IE.Document.parentWindow.Prog1(i2).bgcolor = BackCol
iProgress = 0
End Sub

'--resize and/or position window. Use -1 For any value Not being Set.
Public Sub Move(PixLeft, PixTop, PixWidth, PixHeight)
On Error Resume Next
If (PixLeft > -1) Then IE.Left = PixLeft
If (PixTop > -1) Then IE.Top = PixTop
If (PixWidth > 0) Then IE.Width = PixWidth
If (PixHeight > 0) Then IE.Height = PixHeight
End Sub

'------------- Set background picture: ---------------------
Public Property Let BackGround(sPic)
Dim Boo1, sFil, sFilPath
On Error Resume Next
If (Len(sPic) = 0) or (FSO.FileExists(sPic) = False) Then
Boo1 = IE.Document.Body.removeAttribute("Background", 0)
sFil = FSO.GetFileName(sPic)
sFilPath = sTemp & "\" & sFil
If FSO.FileExists(sFilPath) Then FSO.DeleteFile sFilPath, True
FSO.CopyFile sPic, sFilPath, True
IE.Document.Body.background = sFil
End If
End Property

'------------- Set background color: ---------------------

Public Property Let BackColor(sCol)
If (TestColor(sCol) = True) Then
BackCol = scol
IE.Document.bgColor = sCol
End If
End Property

'------------- Set caption color: ---------------------

Public Property Let TextColor(sCol)
If (TestColor(sCol) = True) Then IE.Document.Body.Text = sCol
End Property

'------------- Set progress color: ---------------------
'-- this must be set before any Advance calls, or after a Reset call, in order to avoid multi-colored units.
Public Property Let ProgressColor(sCol)
If (TestColor(sCol) = True) Then ProgressCol = sCol
End Property

'------------- Set icon: ---------------------

Public Property Let Icon(sPic)
Dim sTag, sFil, sFilPath
On Error Resume Next
If (Len(sPic) = 0) or (FSO.FileExists(sPic) = False) Then Exit Property
sFil = FSO.GetFileName(sPic)
sFilPath = sTemp & "\" & sFil
If FSO.FileExists(sFilPath) Then FSO.DeleteFile sFilPath, True
FSO.CopyFile sPic, sFilPath, True
sTag = "<IMG SRC=" & Q2 & sFil & Q2 & " ALIGN=" & Q2 & "Left" & Q2 & ">"
IE.Document.Body.insertAdjacentHTML "AfterBegin", sTag
End Property

'------------- Set title text: ---------------------

Public Property Let Title(sCap)
IE.Document.Title = sCap
End Property

'------------- Set caption text: ---------------------

Public Property Let Caption(sCap)
IE.Document.parentWindow.Cap1.innerText = sCap
End Property

Public Property Let Units(iNum)
ProgNum = iNum
End Property

'--remove Registry settings that display advertising in the IE title bar.
'-- This change won't show up the first time it's used because the IE
'-- instance has already been created when the method is called.

Public Sub CleanIETitle()
Dim sR1, sR2, SH
On Error Resume Next
sR1 = "HKLM\Software\Microsoft\Internet Explorer\Main\Window Title"
sR2 = "HKCU\Software\Microsoft\Internet Explorer\Main\Window Title"
Set SH = CreateObject("WScript.Shell")
SH.RegWrite sR1, "", "REG_SZ"
SH.RegWrite sR2, "", "REG_SZ"
Set SH = Nothing
End Sub

'----------------- ////////////////////// Private functions /////////////////////////// ------------------------------

'--confirm that color variables are valid 6-character hex color codes:
'-- If Not 6 characters Then TestColor = False
'-- If any character is Not 0-9 or A-F Then TestColor = False

Private Function TestColor(Col6)
Dim iB, sB, iB2, Boo1
On Error Resume Next
TestColor = False
If (Len(Col6) <> 6) Then Exit Function
For iB = 1 to 6
sB = Mid(Col6, iB, 1)
iB2 = Asc(UCase(sB))
If ((iB2 > 47) and (iB2 < 58)) or ((iB2 > 64) and (iB2 < 71)) Then
Boo1 = True
Boo1 = False
Exit For
End If
If (Boo1 = True) Then TestColor = True
End Function

'-- Write the initial webpage, with default values for properties. ------------------
Private Sub PrepPage()
Dim s, i, TS
On Error Resume Next

s = "<HTML><HEAD><TITLE>" & ProgTitle & "</TITLE></HEAD>"
s = s & "<BODY SCROLL=" & Q2 & "NO" & Q2 & " BGCOLOR=" & Q2 & "#E0E0E4" & Q2 & " TEXT=" & Q2 & "#000000" & Q2 & ">"
s = s & "<FONT FACE=" & Q2 & "arial" & Q2 & " SIZE=2><LABEL ID=" & Q2 & "Cap1" & Q2 & ">" & strInitialCaption & "</LABEL></FONT><BR><BR>"
For i = 1 to ProgressUnits
s = s & "<TD WIDTH=16 HEIGHT=16 ID=" & Q2 & "Prog1" & Q2 & ">"

s = s & "</TR></TABLE></TD></TR></TABLE><BR><BR></BODY></HTML>"

Set TS = FSO.CreateTextFile(sTemp & "\iebar3.html", True)

TS.Write s

Set TS = Nothing

IE.Navigate "file:///" & sTemp & "\iebar3.html"
End Sub

End Class
Answered 12/15/2010 by: VBScab
Red Belt

Please log in to comment
Thank you very mutch! This is perfect!
One more thing, can you help me to show this message "always on top" ?
Answered 12/16/2010 by: theicewarrior
Senior Yellow Belt

Please log in to comment
Google for 'VBScript +AppActivate'. I seem to recall seeing a script that would minimise all other windows. Somewhere...
Answered 12/16/2010 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity