How to use Vbscript to time copying a file to memory

Hi Experts,

I would like to use Vbscript running from a command line that will time how long it takes to copy a file to memory.

The goal is to be able to measure the speed of a LAN connection.  
By copying a Server file to workstation memory rather than to hard disk, the results shouldn't be influenced by the destination hard disk speed.

Regards,
Leigh
LVL 1
LeighWardleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lester_ClaytonCommented:
Here ya go. With this script, it will take all the files you pass to it as arguments (even if it's just one), and copy them to memory.
Option Explicit
On Error Resume Next
 
Dim objFSO, objArgs, strArg
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
 
For Each strArg in objArgs
  objFSO.CopyFile strArg, "NUL"
Next

Open in new window

0
LeighWardleAuthor Commented:
Hi Lester,

That code looks good.
Can you just modify it to output the elapsed time, as asked in the question.

Thanks,

Regards,
Leigh
0
Lester_ClaytonCommented:
Yup, no problemmo here you go.
Option Explicit
 
Dim objFSO, objArgs, strArg, Start, Finish, StartSecs, FinishSecs, ElapsedSecs, TotalSizes, File, Speed
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
 
Start = Now
StartSecs = Hour(Start)*360 + Minute(Start)*60 + Second(Start)
For Each strArg in objArgs
  Set File = objFSO.GetFile(strArg)
  TotalSizes = TotalSizes + File.Size
  objFSO.CopyFile strArg, "NUL"
Next
Finish = Now
FinishSecs = Hour(Finish)*360 + Minute(Finish)*60 + Second(Finish)
ElapsedSecs = FinishSecs - StartSecs
if ElapsedSecs > 0 Then
  Speed = TotalSizes / ElapsedSecs / 1024
Else
	Speed = "Undetermined"
End If
WScript.Echo "Start : " & Start & " Finish : " & Finish & " Duration in seconds : " & ElapsedSecs & " Total Bytes Copied : " & TotalSizes & " Speed " & Speed & " kB/sec"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeighWardleAuthor Commented:
Thanks, Lester.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.