Jump to content

Need help with VBS Progress Bar for file copy

Recommended Posts

Okay, so I created this VBS file that executes at RunonceEx after XP installs. It copies all the files from the installation source (dynamically gets the source location from the reg key "SourcePath") to C:\Windows\Cabs.

Option Explicit

Dim WSHShell, RegKey, Sourcepath, Result, fso
Set WSHShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

RegKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\"
Sourcepath = WSHShell.RegRead (regkey & "SourcePath")


fso.CopyFolder Sourcepath & "*", "c:\Windows\Cabs\",TRUE

WSHShell.RegWrite regkey & "Sourcepath", "C:\Windows\Cabs", "REG_SZ"
WSHShell.RegWrite regkey & "ServicePackSourcepath", "C:\Windows\Cabs", "REG_SZ"

When this runs, all I see is a cmd prompt...then it goes away when its done.

What I need help with is how to get a Progress Bar to display the file copy process so you have an idea how much time is left.

Any thoughts?

Link to comment
Share on other sites

You need to use a different object in the script that allow for the progress bar.

Here is your script with some changes made. I have not tested this script.

Save As CopySource.vbs

Option Explicit

Dim Act :Set Act = CreateObject("WScript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Shl :Set Shl = CreateObject("Shell.Application")
Dim Folder, RegKey, Sourcepath

RegKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\"
Sourcepath = Act.RegRead(RegKey & "SourcePath")

If Not Fso.FolderExists("c:\Windows\Cabs") Then Fso.CreateFolder("c:\Windows\Cabs")

Set Folder = Shl.NameSpace(Sourcepath)
Folder.CopyHere "c:\Windows\Cabs\", FOF_CREATEPROGRESSDLG

Act.RegWrite regkey & "Sourcepath", "C:\Windows\Cabs", "REG_SZ"
Act.RegWrite regkey & "ServicePackSourcepath", "C:\Windows\Cabs", "REG_SZ"

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.

  • Create New...