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.CreateFolder("c:\Windows\Cabs")

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
Const FOF_CREATEPROGRESSDLG = &H0&

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...