Copy codeThe Code is as follows: Option Explicit
Dim oBar
Set oBar = New ProgressBar
OBar. StartBar "This is a test ."
WScript. Sleep (3000)
OBar. SetLine "So is this ."
WScript. Sleep (3000)
OBar. CloseBar
Class ProgressBar
Dim oBarCat, sProgressBarHTAFile, sProgressBarRunFile, sProgressBarSleepFile, sInitialTempBuild
Public Sub StartBar (sMessageToDisplay)
Dim sInitialTemp, I
ExecuteGlobal "Dim oShell, oFSO, oEnv"
Set oShell = CreateObject ("Wscript. Shell ")
Set oFSO = CreateObject ("Scripting. FileSystemObject ")
Set oEnv = oShell. Environment ("Process ")
For I = 1 To 16
SInitialTempBuild = sInitialTempBuild & Chr (fRand (97,122 ))
Next
SInitialTemp = oFSO. GetDriveName (oEnv ("TEMP") & "\" & sInitialTempBuild & "\" & oFSO. GetFileName (fGetTempName)
SProgressBarHTAFile = Left (sInitialTemp, (Len (sInitialTemp)-4) & ". hta"
SProgressBarRunFile = Left (sProgressBarHTAFile, Len (sProgressBarHTAFile)-4) & ". run"
SProgressBarSleepFile = Left (sProgressBarHTAFile, Len (sProgressBarHTAFile)-4) & "sleep. vbs"
Set oBarCat = CreateObject ("Scripting. Dictionary ")
OBarCat. Add oBarCat. Count, "OBarCat. Add oBarCat. Count, "OBarCat. Add oBarCat. Count, "<title id =" & Chr (34) & "title" & Chr (34) & "> Please Wait </title>"
OBarCat. Add oBarCat. Count, "<HTA: APPLICATION"
OBarCat. Add oBarCat. Count, "ID =" & Chr (34) & "StatusBar" & Chr (34 )&""
OBarCat. Add oBarCat. Count, "APPLICATIONNAME =" & Chr (34) & "StatusBar" & Chr (34 )&""
OBarCat. Add oBarCat. Count, "SCROLL =" & Chr (34) & "NO" & Chr (34 )&""
OBarCat. Add oBarCat. Count, "SINGLEINSTANCE =" & Chr (34) & "YES" & Chr (34 )&""
OBarCat. Add oBarCat. Count, "CAPTION =" & Chr (34) & "NO" & Chr (34 )&""
OBarCat. Add oBarCat. Count, "BORDER =" & Chr (34) & "NO" & Chr (34 )&""
OBarCat. Add oBarCat. Count, "BORDERSTYLE =" & Chr (34) & "NORMAL" & Chr (34 )&""
OBarCat. Add oBarCat. Count, "SYSMENU =" & Chr (34) & "NO" & Chr (34 )&""
OBarCat. Add oBarCat. Count, "CONTEXTMENU =" & Chr (34) & "NO" & Chr (34 )&""
OBarCat. Add oBarCat. Count, "SHOWINTASKBAR =" & Chr (34) & "NO" & Chr (34 )&""
OBarCat. Add oBarCat. Count, "/>"
OBarCat. Add oBarCat. Count, "<SCRIPT Language =" & Chr (34) & "VBScript" & Chr (34) & ">"
OBarCat. Add oBarCat. Count, "Dim oShell, iTimer1, iTimer2, sStatusBarAsciiText, sPID, iCID, sStatusMsg"
OBarCat. Add oBarCat. Count, "Set oShell = CreateObject (" & Chr (34) & "Wscript. Shell" & Chr (34 )&")"
OBarCat. Add oBarCat. Count, "sPID =" & Chr (34) & "& Chr (34) &": iCID = 10"
OBarCat. Add oBarCat. Count, "Sub Window_Onload"
OBarCat. Add oBarCat. Count, "window. resizeTo 320,250"
OBarCat. add oBarCat. count, "CreateObject (" & Chr (34) & "Scripting. fileSystemObject "& Chr (34 )&"). createTextFile ("& Chr (34) & sProgressBarRunFile & Chr (34 )&")"
OBarCat. add oBarCat. count, "CreateObject (" & Chr (34) & "Scripting. fileSystemObject "& Chr (34 )&"). createTextFile ("& Chr (34) & sProgressBarSleepFile & Chr (34 )&")"
OBarCat. add oBarCat. count, "CreateObject (" & Chr (34) & "Scripting. fileSystemObject "& Chr (34 )&"). openTextFile ("& Chr (34) & sProgressBarSleepFile & Chr (34) &", 2 ). writeLine "& Chr (34) &" WScript. sleep (1000) "& Chr (34 )&""
OBarCat. Add oBarCat. Count, "iTimer1 = window. setInterval (" & Chr (34) & "Do_Refresh" & Chr (34) & ", 175 )"
OBarCat. Add oBarCat. Count, "iTimer2 = window. setInterval (" & Chr (34) & "Do_Nothing" & Chr (34) & ", 500 )"
OBarCat. Add oBarCat. Count, "End Sub"
OBarCat. Add oBarCat. Count, "Sub Do_Nothing"
OBarCat. add oBarCat. count, "If CreateObject (" & Chr (34) & "Scripting. fileSystemObject "& Chr (34 )&"). fileExists ("& Chr (34) & sProgressBarRunFile & Chr (34) &") Then"
OBarCat. Add oBarCat. Count, "Dim oWMIService, cItems, oItem"
OBarCat. Add oBarCat. Count, "Set oWMIService = GetObject (" & Chr (34) & "winmgmts: \. \ root \ CIMV2" & Chr (34 )&")"
OBarCat. add oBarCat. count, "Set cItems = oWMIService. execQuery ("& Chr (34) &" SELECT Name, ExecutablePath, CommandLine FROM Win32_Process where Name = 'mshta.exe '"& Chr (34 )&")"
OBarCat. Add oBarCat. Count, "For Each oItem in cItems"
OBarCat. Add oBarCat. Count, "If oItem. CommandLine = document. Location. pathname Then"
OBarCat. Add oBarCat. Count, "oShell. AppActivate oItem. Handle"
OBarCat. Add oBarCat. Count, "End If"
OBarCat. Add oBarCat. Count, "Next"
OBarCat. Add oBarCat. Count, "Else"
OBarCat. add oBarCat. count, "CreateObject (" & Chr (34) & "Scripting. fileSystemObject "& Chr (34 )&"). deleteFile "& Chr (34) & sProgressBarSleepFile & Chr (34) &", True"
OBarCat. Add oBarCat. Count, "window. clearInterval (iTimer1 )"
OBarCat. Add oBarCat. Count, "window. clearInterval (iTimer2 )"
OBarCat. Add oBarCat. Count, "self. Close"
OBarCat. Add oBarCat. Count, "End If"
OBarCat. Add oBarCat. Count, "End Sub"
OBarCat. Add oBarCat. Count, "Sub Do_Refresh"
OBarCat. Add oBarCat. Count, "Select Case iCID"
OBarCat. Add oBarCat. Count, "Case 10"
OBarCat. Add oBarCat. Count, "sStatusBarAsciiText =" & Chr (34) & "ooooo" & Chr (34) & ": iCID = 0"
OBarCat. Add oBarCat. Count, "Case 0"
OBarCat. Add oBarCat. Count, "sStatusBarAsciiText =" & Chr (34) & "oooon" & Chr (34) & ": iCID = 1"
OBarCat. Add oBarCat. Count, "Case 1"
OBarCat. Add oBarCat. Count, "sStatusBarAsciiText =" & Chr (34) & "ooono" & Chr (34) & ": iCID = 2"
OBarCat. Add oBarCat. Count, "Case 2"
OBarCat. Add oBarCat. Count, "sStatusBarAsciiText =" & Chr (34) & "oonoo" & Chr (34) & ": iCID = 3"
OBarCat. Add oBarCat. Count, "Case 3"
OBarCat. Add oBarCat. Count, "sStatusBarAsciiText =" & Chr (34) & "onooo" & Chr (34) & ": iCID = 4"
OBarCat. Add oBarCat. Count, "Case 4"
OBarCat. Add oBarCat. Count, "sStatusBarAsciiText =" & Chr (34) & "noooo" & Chr (34) & ": iCID = 5"
OBarCat. Add oBarCat. Count, "Case 5"
OBarCat. Add oBarCat. Count, "sStatusBarAsciiText =" & Chr (34) & "onooo" & Chr (34) & ": iCID = 6"
OBarCat. Add oBarCat. Count, "Case 6"
OBarCat. Add oBarCat. Count, "sStatusBarAsciiText =" & Chr (34) & "oonoo" & Chr (34) & ": iCID = 7"
OBarCat. Add oBarCat. Count, "Case 7"
OBarCat. Add oBarCat. Count, "sStatusBarAsciiText =" & Chr (34) & "ooono" & Chr (34) & ": iCID = 8"
OBarCat. Add oBarCat. Count, "Case 8"
OBarCat. Add oBarCat. Count, "sStatusBarAsciiText =" & Chr (34) & "oooon" & Chr (34) & ": iCID = 1"
OBarCat. Add oBarCat. Count, "End Select"
OBarCat. Add oBarCat. Count, "Stats. innerHTML = sStatusBarAsciiText"
OBarCat. Add oBarCat. Count, "On Error Resume Next"
OBarCat. Add oBarCat. Count, "oShell. RegRead (" & Chr (34) & "HKLM \ SYSTEM \ ProgressBar \ MSG" & Chr (34 )&")"
OBarCat. Add oBarCat. Count, "iRegErr = Err. Number"
OBarCat. Add oBarCat. Count, "On Error Goto 0"
OBarCat. Add oBarCat. Count, "If iRegErr = 0 then"
OBarCat. add oBarCat. count, "sStatusMsg = Replace (oShell. regRead ("& Chr (34) &" HKLM \ SYSTEM \ ProgressBar \ MSG "& Chr (34) &"), VbCrLf, "& Chr (34) & "<br>" & Chr (34 )&")"
OBarCat. Add oBarCat. Count, "Else"
OBarCat. Add oBarCat. Count, "sStatusMsg =" & Chr (34) & "" & Chr (34 )&""
OBarCat. Add oBarCat. Count, "End if"
OBarCat. Add oBarCat. Count, "MyMsg. innerHTML = sStatusMsg"
OBarCat. Add oBarCat. Count, "End Sub"
OBarCat. Add oBarCat. Count, "</SCRIPT>"
OBarCat. Add oBarCat. Count, "<style>"
OBarCat. Add oBarCat. Count, "body, td, a {font-family: Arial; font-size: 12px; text-decoration: none; color: black ;}"
OBarCat. Add oBarCat. Count, "body {filter: progid: DXImageTransform. Microsoft. Gradient (GradientType = 0, StartColorStr = '# 9999FF', EndColorStr = '# ffff ')}"
OBarCat. Add oBarCat. Count, ". pix {width: 1px; height 1px ;}"
OBarCat. Add oBarCat. Count, "</style>"
OBarCat. Add oBarCat. Count, "OBarCat. Add oBarCat. Count, "<body>"
OBarCat. Add oBarCat. Count, "<center>"
OBarCat. Add oBarCat. Count, "<table width =" & Chr (34) & "275" & Chr (34) & ">"
OBarCat. Add oBarCat. Count, "<tr> <td>"
OBarCat. add oBarCat. count, "<fieldset> <legend align =" & Chr (34) & "center" & Chr (34) & "> <B> Please Be Patient </B> </legend>"
OBarCat. Add oBarCat. Count, "<br> <center>"
OBarCat. add oBarCat. count, "<span id =" & Chr (34) & "Stats" & Chr (34) & "style =" & Chr (34) & "font-family: wingdings; font-weight: bold; font-size: 20px; "& Chr (34) &"> </span>"
OBarCat. Add oBarCat. Count, "</center> <br>"
OBarCat. Add oBarCat. Count, "</fieldset>"
OBarCat. Add oBarCat. Count, "</td> </tr>"
OBarCat. Add oBarCat. Count, "</table>"
OBarCat. add oBarCat. count, "<span id =" & Chr (34) & "MyMsg" & Chr (34) & "style =" & Chr (34) & "font-family: Ariel; font-size: 12px; "& Chr (34) &"> </span>"
OBarCat. Add oBarCat. Count, "</body>"
OBarCat. Add oBarCat. Count, "SubWriteFile sProgressBarHTAFile, Join (oBarCat. Items, VbCrLf)
OShell. RegWrite "HKLM \ SYSTEM \ ProgressBar \ MSG", sMessageToDisplay, "REG_SZ"
OShell. Run sProgressBarHTAFile, 1, False
End Sub
Public Sub CloseBar ()
FKillFile sProgressBarRunFile
Dim sProgressBarHTAFileKiller
SubKillRegKey "HKLM \ SYSTEM \ ProgressBar", "DELETE"
SProgressBarHTAFileKiller = oFSO. GetDriveName (oEnv ("TEMP") & "\ htakiller. vbs"
SubWriteFile sProgressBarHTAFileKiller, "On Error Resume Next"
SubWriteFile sProgressBarHTAFileKiller, "wscript. sleep (10000 )"
SubWriteFile sProgressBarHTAFileKiller, "Set oFSO = CreateObject (" "Scripting. FileSystemObject "")"
SubWriteFile sProgressBarHTAFileKiller, "oFSO. DeleteFile" & Chr (34) & sProgressBarHTAFile & Chr (34) & ", True"
SubWriteFile sProgressBarHTAFileKiller, "oFSO. deleteFolder "& Chr (34) & oFSO. getDriveName (oEnv ("TEMP") & "\" & sInitialTempBuild & Chr (34) & ", True"
SubWriteFile sProgressBarHTAFileKiller, "oFSO. DeleteFile" & Chr (34) & sProgressBarHTAFileKiller & Chr (34) & ", True"
OShell. Run "% comspec %/c cscript.exe" & sProgressBarHTAFileKiller, 0, False
End Sub
Public Sub SetLine (sNewText)
OShell. RegWrite "HKLM \ SYSTEM \ ProgressBar \ MSG", sNewText, "REG_SZ"
End Sub
Private Function fGetTempName ()
Dim iFilenameCharacters, iHighestASCiiValue, iLowestASCiiValue
Dim iCharASCiiValue, sTmpFileName, oTempNameDic
Set oTempNameDic = CreateObject ("Scripting. Dictionary ")
IFilenameCharacters = 8
IHighestASCiiValue = 126
ILowestASCiiValue = 46
STmpFileName = ""
Randomize
Do
ICharASCiiValue = Int (iHighestASCiiValue-iLowestASCiiValue + 1) * Rnd) + iLowestASCiiValue)
Select Case True
Case iCharASCiiValue = 47
Case iCharASCiiValue> 57 And iCharASCiiValue <95
Case iCharASCiiValue = 96
Case iCharASCiiValue> 122 And iCharASCiiValue <126
Case Else
OTempNameDic. Add oTempNameDic. Count, Chr (iCharASCiiValue)
End Select
Loop While oTempNameDic. Count <iFilenameCharacters
FGetTempName = oEnv ("TEMP") & "\" & Join (oTempNameDic. Items, "") & ". tmp"
OTempNameDic. RemoveAll
End Function
Private Function fKillFile (sFileToKill)
Dim iErr, sErr
Select Case True
Case InStr (sFileToKill, "*") <> 0
If oFSO. FolderExists (oFSO. GetParentFolderName (sFileToKill) Then
On Error Resume Next
OFSO. DeleteFile sFileToKill, True
IErr = Err. Number
SErr = Err. Description
On Error GoTo 0
If iErr = 53 Then iErr = 0
End If
Case oFSO. FileExists (sFileToKill)
On Error Resume Next
OFSO. DeleteFile sFileToKill, True
IErr = Err. Number
SErr = Err. Description
On Error GoTo 0
End Select
Select Case iErr
Case 0
FKillFile = 0
Case Else
FKillFile = sErr
End Select
End Function
Private Function fRand (iLowerLimit, iUpperLimit)
ExecuteGlobal "Dim bRandomized"
If bRandomized <> True Then Randomize
BRandomized = True
FRand = Int (iUpperLimit-iLowerLimit + 1) * Rnd () + iLowerLimit)
End Function
Private Sub subWriteFile (sFileToWrite, sTextToWrite)
Dim oFileToWrite
SubCreateFile sFileToWrite
Set oFileToWrite = oFSO. OpenTextFile (sFileToWrite, 8)
OFileToWrite. WriteLine sTextToWrite
OFileToWrite. Close
End Sub
Private Sub subCreateFile (sFileToCreate)
SubCreateFolder oFSO. GetParentFolderName (sFileToCreate)
If Not oFSO. FileExists (sFileToCreate) Then oFSO. CreateTextFile (sFileToCreate)
End Sub
Private Sub subCreateFolder (sFolderPathToCreate)
If Trim (sFolderPathToCreate) <> "Then
If oFSO. FolderExists (sFolderPathToCreate) Then
Exit Sub
Else
SubCreateFolder (oFSO. GetParentFolderName (sFolderPathToCreate ))
End If
OFSO. CreateFolder (sFolderPathToCreate)
End If
End Sub
Private Sub subKillRegKey (ByVal sKeyToDelete, sDeleteConfirmation)
Dim aSubKeys, sSubKey, iSubkeyCheck, sKeyToKill, iElement
Dim aKeyPathSubSection, hKeyRoot, oWMIReg, sKeyRoot
Const HKEY_CLASSES_ROOT = & H80000000
Const HKEY_CURRENT_USER = & H80000001
Const HKEY_LOCAL_MACHINE = & H80000002
Const HKEY_USERS = & H80000003
Const HKEY_CURRENT_CONFIG = & H80000005
If sDeleteConfirmation <> "DELETE" Then Exit Sub
AKeyPathSubSection = Split (sKeyToDelete ,"\")
Select Case UCase (aKeyPathSubSection (0 ))
Case "HKEY_CLASSES_ROOT", "HKCR"
HKeyRoot = HKEY_CLASSES_ROOT
SKeyRoot = "HKEY_CLASSES_ROOT"
Case "HKEY_CURRENT_USER", "HKCU"
HKeyRoot = HKEY_CURRENT_USER
SKeyRoot = "HKEY_CURRENT_USER"
Case "HKEY_LOCAL_MACHINE", "HKLM"
HKeyRoot = HKEY_LOCAL_MACHINE
SKeyRoot = "HKEY_LOCAL_MACHINE"
Case "HKEY_USERS", "HKU"
HKeyRoot = HKEY_USERS
SKeyRoot = "HKEY_USERS"
Case "HKEY_CURRENT_CONFIG"
HKeyRoot = HKEY_CURRENT_CONFIG
SKeyRoot = "HKEY_CURRENT_CONFIG"
Case Else
SubKillRegKey = 1
Exit Sub
End Select
For iElement = 1 To UBound (aKeyPathSubSection)
SKeyToKill = sKeyToKill & "\" & aKeyPathSubSection (iElement)
Next
If Left (sKeyToKill, 1) = "\" Then sKeyToKill = Right (sKeyToKill, Len (sKeyToKill)-1)
On Error Resume Next
Set oWMIReg = GetObject ("winmgmts: {impersonationLevel = impersonate }! \. \ Root \ default: StdRegProv ")
ISubkeyCheck = oWMIReg. EnumKey (hKeyRoot, sKeyToKill, aSubKeys)
If iSubkeyCheck = 0 And IsArray (aSubKeys) Then
For Each sSubKey In aSubKeys
If Err. Number <> 0 Then
Err. Clear
Exit Sub
End If
SubKillRegKey sKeyRoot & "\" & sKeyToKill & "\" & sSubKey, "DELETE"
Next
End If
OWMIReg. DeleteKey hKeyRoot, sKeyToKill
End Sub
End Class