How to use Vbscript to time a web page download

Hi Experts,

I would like to use Vbscript running from a command line that will time how long it takes to download a given URL.

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.

LeighWardleAuthor Commented:
Something like this would do the trick, it just needs some code for timing the download...

    http://blog.netnerds.net/2007/01/vbscript-download-and-save-a-binary-file/

Regards,
Leigh
0
RobSampsonCommented:
G'Day Leigh, how was your Australia Day weekend?  Hope you had a good one....it was great weather, so that's a start!

Taking a leaf from the article you posted, this should tell you the time taken ( I think it's in milliseconds...)

'=======================
' Download_A_File_And_Display_Time_Taken.vbs
strURL = "http://www.haase-online.de/dirk/maczip/download/MacZipDocs.zip"
strLocalFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & Mid(strURL, InStrRev(strURL, "/") + 1)

dteStart = Timer

' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

objXMLHTTP.open "GET", strURL, False
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
      Set objADOStream = CreateObject("ADODB.Stream")
      objADOStream.Open
      objADOStream.Type = 1 'adTypeBinary
      
      objADOStream.Write objXMLHTTP.ResponseBody
      objADOStream.Position = 0    'Set the stream position to the start
      
      Set objFSO = Createobject("Scripting.FileSystemObject")
      If objFSO.Fileexists(strLocalFile) Then objFSO.DeleteFile strLocalFile
      Set objFSO = Nothing
      
      objADOStream.SaveToFile strLocalFile
      objADOStream.Close
      Set objADOStream = Nothing
End If

Set objXMLHTTP = Nothing

dteEnd = Timer

MsgBox "Download complete." & VbCrLf & _
      "Source: " & strURL & VbCrLf & _
      "Target: " & strLocalFile & VbCrLf & _
      "Time taken: " & dteEnd - dteStart & " milliseconds."
'=======================

Regards,

Rob.
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:
Hi Rob,

Had a great weekend at Sandy Point, great weather!

Your solution worked a treat.
The only issue is that I think the time output is in seconds, not milliseconds.
I have a sample file (it's about 3 mb):

strURL = "http://www.mincad.com.au/forum/files/CIRCLY_5.0_Service_Pack.exe"

I would like to be able to clear the cache, as a 2nd or subsequent download of the same URL is almost instantaneous.  If that's too hard I will raise it as another Question.

Regards,
Leigh

0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

RobSampsonCommented:
This should delete all of the temporary internet files as well....

'=======================
' Download_A_File_And_Display_Time_Taken.vbs
strURL = "http://www.mincad.com.au/forum/files/CIRCLY_5.0_Service_Pack.exe"
strLocalFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & Mid(strURL, InStrRev(strURL, "/") + 1)

dteStart = Timer

' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

objXMLHTTP.open "GET", strURL, False
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
      Set objADOStream = CreateObject("ADODB.Stream")
      objADOStream.Open
      objADOStream.Type = 1 'adTypeBinary
     
      objADOStream.Write objXMLHTTP.ResponseBody
      objADOStream.Position = 0    'Set the stream position to the start
     
      Set objFSO = Createobject("Scripting.FileSystemObject")
      If objFSO.Fileexists(strLocalFile) Then objFSO.DeleteFile strLocalFile
      Set objFSO = Nothing
     
      objADOStream.SaveToFile strLocalFile
      objADOStream.Close
      Set objADOStream = Nothing
End If

Set objXMLHTTP = Nothing

dteEnd = Timer

' Delete the temporary internet files
Set objShell = CreateObject("WScript.Shell")
strTempFiles = objShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Local Settings\Temporary Internet Files"
Set objFSO = CreateObject("Scripting.FileSystemObject")
strTempFiles = objFSO.GetFolder(strTempFiles).ShortPath
strCommand = "cmd /c del /q /f /s " & strTempFiles & "\*.*"
objShell.Run strCommand, 0, True
Set objFSO = Nothing
Set objShell = Nothing

MsgBox "Download complete." & VbCrLf & _
      "Source: " & strURL & VbCrLf & _
      "Target: " & strLocalFile & VbCrLf & _
      "Time taken: " & dteEnd - dteStart & " seconds."
'=======================


Regards,

Rob.
0
LeighWardleAuthor Commented:
Hi Rob,

Thanks for the updated version.

But it doesn't appear to clear the cache...
The time I run it it takes 4 seconds, then subsequent runs take 0.2 seconds.

Regards,
Leigh
0
RobSampsonCommented:
Hmmm, try this and see if the command is actually deleting the Temp Internet Files:

'=======================
' Download_A_File_And_Display_Time_Taken.vbs
strURL = "http://www.mincad.com.au/forum/files/CIRCLY_5.0_Service_Pack.exe"
strLocalFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & Mid(strURL, InStrRev(strURL, "/") + 1)

dteStart = Timer

' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

objXMLHTTP.open "GET", strURL, False
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
      Set objADOStream = CreateObject("ADODB.Stream")
      objADOStream.Open
      objADOStream.Type = 1 'adTypeBinary
     
      objADOStream.Write objXMLHTTP.ResponseBody
      objADOStream.Position = 0    'Set the stream position to the start
     
      Set objFSO = Createobject("Scripting.FileSystemObject")
      If objFSO.Fileexists(strLocalFile) Then objFSO.DeleteFile strLocalFile
      Set objFSO = Nothing
     
      objADOStream.SaveToFile strLocalFile
      objADOStream.Close
      Set objADOStream = Nothing
End If

Set objXMLHTTP = Nothing

dteEnd = Timer

' Delete the temporary internet files
Set objShell = CreateObject("WScript.Shell")
strTempFiles = objShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Local Settings\Temporary Internet Files\Content.IE5"
Set objFSO = CreateObject("Scripting.FileSystemObject")
strTempFiles = objFSO.GetFolder(strTempFiles).ShortPath
strCommand = "cmd /k del /q /f /s " & strTempFiles & "\*.*"
objShell.Run strCommand, 1, True
Set objFSO = Nothing
Set objShell = Nothing

MsgBox "Download complete." & VbCrLf & _
      "Source: " & strURL & VbCrLf & _
      "Target: " & strLocalFile & VbCrLf & _
      "Time taken: " & dteEnd - dteStart & " seconds."
'=======================

Regards,

Rob.
0
LeighWardleAuthor Commented:
Sorry, Rob, that version displays a command prompt with this error:

C:\DOCUME~1\Echidna\LOCALS~1\TEMPOR~1\Content.IE5\index.dat
The process cannot access the file because it is being used by another process.

Regards,
Leigh
0
RobSampsonCommented:
Hmmm, OK, so that file is open then....try this line for the strCommand instead....
strCommand = "cmd /c for /F ""tokens=* delims="" %f in ('dir /b /s " & strTempFiles & "') do @del /q %f"

Regards,

Rob.
0
LeighWardleAuthor Commented:
Hi Rob,

That change made the command prompt error go away.

But it must still be using the cached version - every  run  takes about 0.2 seconds, not the 4 seconds for a clean download.

Sorry it's a headache for you....

Regards,
Leigh
0
RobSampsonCommented:
If you delete the Temporary Internet Files via the Tools --> Internet Options menu, does it take the three seconds again? The reason I ask is that maybe you are going through a third party cache / proxy that is caching it elsewhere?

Oh, whoops, if you change the cmd /c to cmd /k above, do you see the files being deleted properly?

Regards,

Rob.
0
LeighWardleAuthor Commented:
If I delete the Temporary Internet Files via the Tools --> Internet Options menu,  it takes the full  three seconds again.

When I change the cmd /c to cmd /k above, I can see this error:

C:\DOCUME~1\Echidna\LOCALS~1\TEMPOR~1\Content.IE5\index.dat
The process cannot access the file because it is being used by another process.


Regards,
0
RobSampsonCommented:
With this though:
strCommand = "cmd /k for /F ""tokens=* delims="" %f in ('dir /b /s " & strTempFiles & "') do @del /q %f"

does it try to delete more than 1 file?  Hmmm, if not, I'll have to look at another method....

Regards,

Rob.
0
LeighWardleAuthor Commented:
That version of strCommand= is what I just ran before.
How can I see if it is trying to delete more than one file?

Regards,
Leigh
0
RobSampsonCommented:
Leight, please try this:

What this should do is tick the box in Tools --> Internet Options --> Advanced --> Empty Temporary Internet Files folder when browser is closed.  That should delete the files before you re-run the script again.

'=======================
' Download_A_File_And_Display_Time_Taken.vbs
strURL = "http://www.mincad.com.au/forum/files/CIRCLY_5.0_Service_Pack.exe"
strLocalFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & Mid(strURL, InStrRev(strURL, "/") + 1)

dteStart = Timer

' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

objXMLHTTP.open "GET", strURL, False
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
      Set objADOStream = CreateObject("ADODB.Stream")
      objADOStream.Open
      objADOStream.Type = 1 'adTypeBinary
     
      objADOStream.Write objXMLHTTP.ResponseBody
      objADOStream.Position = 0    'Set the stream position to the start
     
      Set objFSO = Createobject("Scripting.FileSystemObject")
      If objFSO.Fileexists(strLocalFile) Then objFSO.DeleteFile strLocalFile
      Set objFSO = Nothing
     
      objADOStream.SaveToFile strLocalFile
      objADOStream.Close
      Set objADOStream = Nothing
End If

Set objXMLHTTP = Nothing

dteEnd = Timer

' Delete the temporary internet files
' The script writes to the registry value: Empty Temporary Internet Files
' Note: REG_DWORD (not REG_SZ)
' Note: Logic of 0 (zero = off) means persistent ON - strange but true!
' Zero means it WILL delete the file, 1 means it WON'T delete them.
Set objShell = CreateObject("WScript.Shell")
On Error Resume Next
RegLocate = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Persistent"
objShell.RegWrite RegLocate,"0","REG_DWORD"

' Need to open and close a window to make sure files are deleted
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = False
While objIE.ReadyState <> 4
      WScript.Sleep 100
Wend
objIE.Quit
Set objIE = Nothing

MsgBox "Download complete." & VbCrLf & _
      "Source: " & strURL & VbCrLf & _
      "Target: " & strLocalFile & VbCrLf & _
      "Time taken: " & dteEnd - dteStart & " seconds."
'=======================

Regards,

Rob.
0
LeighWardleAuthor Commented:
Hi Rob,

I ticked the box in Tools --> Internet Options --> Advanced --> Empty Temporary Internet Files folder when browser is closed.

Now when I run the latest version of the script I see the download file appear on my desktop, but there is no message about the time...

Cheers,
Leigh
0
RobSampsonCommented:
Whoops, put this:
objIE.Navigate "http://www.google.com"

under this line:
objIE.Visible = False

Regards,

Rob.
0
RobSampsonCommented:
Oh, and you'll probably have to kill WScript.exe from Task Manager now, I think it will still be running...

Regards,

Rob.
0
LeighWardleAuthor Commented:
Thanks, Rob.

But it's still using the cached version - 4 seconds the first time then about 0.2 seconds subsequently.

P.S. what does objIE.Navigate "http://www.google.com" do?
(It's different from the URL I am downloading?)

Regards,
Leigh
0
RobSampsonCommented:
I'll do some more testing...

The line:
objIE.Navigate "http://www.google.com"

just makes a new browser window visit a page. Google is just a relatively small page, so that it doesn't take too long. I use this to open a browser window, then close it again, hopefully to delete the cache....

Regards,

Rob.
0
RobSampsonCommented:
OK, this should work.  I've move the clear cache block to the top, so you have the option of clearing the cache or not, before downloading the file, via the boolClearCache variable.

'=======================
' Download_A_File_And_Display_Time_Taken.vbs

'======== START OF CLEAR TEMPORARY INTERNET FILES CACHE BLOCK ===========
' Delete the temporary internet files
' SET boolClearCache to True to clear cache before downloading, or set it
' to False to not clear the cache
boolClearCache = True
If boolClearCache = True Then
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objShell = CreateObject("WScript.Shell")
      strTempFiles = objShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Local Settings\Temporary Internet Files\Content.IE5"
      strTempFiles = objFSO.GetFolder(strTempFiles).ShortPath
      For Each objSubFolder In objFSO.GetFolder(strTempFiles).SubFolders
            For Each objFile In objSubFolder.Files
                  On Error Resume Next
                  objFile.Delete True
                  On Error GoTo 0
            Next
      Next
      Set objFSO = Nothing
      Set objShell = Nothing
End If

'======== END OF CLEAR TEMPORARY INTERNET FILES CACHE BLOCK ===========

strURL = "http://www.haase-online.de/dirk/maczip/download/MacZipDocs.zip"
strLocalFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & Mid(strURL, InStrRev(strURL, "/") + 1)

dteStart = Timer

' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

objXMLHTTP.open "GET", strURL, False
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
      Set objADOStream = CreateObject("ADODB.Stream")
      objADOStream.Open
      objADOStream.Type = 1 'adTypeBinary
     
      objADOStream.Write objXMLHTTP.ResponseBody
      objADOStream.Position = 0    'Set the stream position to the start
     
      Set objFSO = Createobject("Scripting.FileSystemObject")
      If objFSO.Fileexists(strLocalFile) Then objFSO.DeleteFile strLocalFile
      Set objFSO = Nothing
     
      objADOStream.SaveToFile strLocalFile
      objADOStream.Close
      Set objADOStream = Nothing
End If

Set objXMLHTTP = Nothing

dteEnd = Timer

MsgBox "Download complete." & VbCrLf & _
      "Source: " & strURL & VbCrLf & _
      "Target: " & strLocalFile & VbCrLf & _
      "Time taken: " & dteEnd - dteStart & " seconds."
'=======================


Regards,

Rob.
0
LeighWardleAuthor Commented:
Thanks, Rob.

I've left boolClearCache as True.

It's still using the cached version - about 5 seconds the first time then about 0.8 seconds subsequently.

Maybe we need to log what's going on with the cache deletes?


Regards,
Leigh
0
RobSampsonCommented:
That's odd....with the sample file that I had it download "MacDocsZip", it takes 5.3 seconds with boolClearCache set to True, and 1.1 seconds with it set to False.

Try this, it should output what is being deleted from the cache to a file called CacheDeleteLog.txt

'=======================
' Download_A_File_And_Display_Time_Taken.vbs

'======== START OF CLEAR TEMPORARY INTERNET FILES CACHE BLOCK ===========
' Delete the temporary internet files
' SET boolClearCache to True to clear cache before downloading, or set it
' to False to not clear the cache
boolClearCache = True
If boolClearCache = True Then
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objShell = CreateObject("WScript.Shell")
      strTempFiles = objShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Local Settings\Temporary Internet Files\Content.IE5"
      strTempFiles = objFSO.GetFolder(strTempFiles).ShortPath
      strCacheLog = "Cache Files Cleared" & VbCrLf & "==================="
      For Each objSubFolder In objFSO.GetFolder(strTempFiles).SubFolders
            For Each objFile In objSubFolder.Files
                  On Error Resume Next
                  objFile.Delete True
                  If Err.Number = 0 Then
                        strCacheLog = strCacheLog & VbCrLf & "SUCCESS: " & objFile.Path
                  Else
                        Err.Clear
                        strCacheLog = strCacheLog & VbCrLf & "FAILURE: " & objFile.Path
                  End If
                  On Error GoTo 0
            Next
      Next
      Set objCacheLog = objFSO.CreateTextFile("CacheDeleteLog.txt", True)
      objCacheLog.Write strCacheLog
      objCacheLog.Close
      Set objCacheLog = Nothing
      Set objFSO = Nothing
      Set objShell = Nothing
End If

'======== END OF CLEAR TEMPORARY INTERNET FILES CACHE BLOCK ===========

strURL = "http://www.haase-online.de/dirk/maczip/download/MacZipDocs.zip"
strLocalFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & Mid(strURL, InStrRev(strURL, "/") + 1)

dteStart = Timer

' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

objXMLHTTP.open "GET", strURL, False
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
      Set objADOStream = CreateObject("ADODB.Stream")
      objADOStream.Open
      objADOStream.Type = 1 'adTypeBinary
     
      objADOStream.Write objXMLHTTP.ResponseBody
      objADOStream.Position = 0    'Set the stream position to the start
     
      Set objFSO = Createobject("Scripting.FileSystemObject")
      If objFSO.Fileexists(strLocalFile) Then objFSO.DeleteFile strLocalFile
      Set objFSO = Nothing
     
      objADOStream.SaveToFile strLocalFile
      objADOStream.Close
      Set objADOStream = Nothing
End If

Set objXMLHTTP = Nothing

dteEnd = Timer

MsgBox "Download complete." & VbCrLf & _
      "Source: " & strURL & VbCrLf & _
      "Target: " & strLocalFile & VbCrLf & _
      "Time taken: " & dteEnd - dteStart & " seconds."
'=======================

Regards,

Rob.
0
LeighWardleAuthor Commented:
Hi Rob,

First run of the new script took 0.8 seconds, so the cache hasn't been cleared.

"CacheDeleteLog.txt" just consists of:
Cache Files Cleared
===================

Regards,
Leigh
0
RobSampsonCommented:
Can you please browse through this folder and see if you can find the file in your cache:
C:\Documents and Settings\username\Local Settings\Temporary Internet Files\Content.IE5

Are you a local Administrator of the computer?

Regards,

Rob.
0
LeighWardleAuthor Commented:
Hi Rob,

MacZipDocs.zip is currently in the folder:
C:\Documents and Settings\Echidna\Local Settings\Temporary Internet Files

Regards,
Leigh
0
RobSampsonCommented:
OK, so I was going one folder too far, try this:

'=======================
' Download_A_File_And_Display_Time_Taken.vbs

'======== START OF CLEAR TEMPORARY INTERNET FILES CACHE BLOCK ===========
' Delete the temporary internet files
' SET boolClearCache to True to clear cache before downloading, or set it
' to False to not clear the cache
boolClearCache = True
If boolClearCache = True Then
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objShell = CreateObject("WScript.Shell")
      strTempFiles = objShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Local Settings\Temporary Internet Files"
      strTempFiles = objFSO.GetFolder(strTempFiles).ShortPath
      strCacheLog = "Cache Files Cleared" & VbCrLf & "==================="
      For Each objFile In objFSO.GetFolder(strTempFiles).Files
            strFilePath = objFile.Path
            On Error Resume Next
            objFSO.DeleteFile strFilePath, True
            If Err.Number = 0 Then
                  strCacheLog = strCacheLog & VbCrLf & "SUCCESS: " & strFilePath
            Else
                  Err.Clear
                  strCacheLog = strCacheLog & VbCrLf & "FAILURE: " & strFilePath
            End If
            On Error GoTo 0
      Next      
      For Each objSubFolder In objFSO.GetFolder(strTempFiles).SubFolders
            Call RecurseSubFolders(objSubFolder)
      Next
      Set objCacheLog = objFSO.CreateTextFile("CacheDeleteLog.txt", True)
      objCacheLog.Write strCacheLog
      objCacheLog.Close
      Set objCacheLog = Nothing
      Set objFSO = Nothing
      Set objShell = Nothing
End If

'======== END OF CLEAR TEMPORARY INTERNET FILES CACHE BLOCK ===========

strURL = "http://www.haase-online.de/dirk/maczip/download/MacZipDocs.zip"
strLocalFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & Mid(strURL, InStrRev(strURL, "/") + 1)

dteStart = Timer

' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

objXMLHTTP.open "GET", strURL, False
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
      Set objADOStream = CreateObject("ADODB.Stream")
      objADOStream.Open
      objADOStream.Type = 1 'adTypeBinary
     
      objADOStream.Write objXMLHTTP.ResponseBody
      objADOStream.Position = 0    'Set the stream position to the start
     
      Set objFSO = Createobject("Scripting.FileSystemObject")
      If objFSO.Fileexists(strLocalFile) Then objFSO.DeleteFile strLocalFile
      Set objFSO = Nothing
     
      objADOStream.SaveToFile strLocalFile
      objADOStream.Close
      Set objADOStream = Nothing
End If

Set objXMLHTTP = Nothing

dteEnd = Timer

MsgBox "Download complete." & VbCrLf & _
      "Source: " & strURL & VbCrLf & _
      "Target: " & strLocalFile & VbCrLf & _
      "Time taken: " & dteEnd - dteStart & " seconds."
     
Sub RecurseSubFolders(objFolder)
      For Each objFile In objFolder.Files
            strFilePath = objFile.Path
            On Error Resume Next
            objFSO.DeleteFile strFilePath, True
            If Err.Number = 0 Then
                  strCacheLog = strCacheLog & VbCrLf & "SUCCESS: " & strFilePath
            Else
                  Err.Clear
                  strCacheLog = strCacheLog & VbCrLf & "FAILURE: " & strFilePath
            End If
            On Error GoTo 0
      Next

      For Each objSubFolder In objFolder.SubFolders
            Call RecurseSubFolders(objSubFolder)
      Next
End Sub
'=======================

Regards,

Rob.
0
LeighWardleAuthor Commented:
Hi Rob,

Still not working...

"CacheDeleteLog.txt" consists of:
Cache Files Cleared
===================
SUCCESS: C:\DOCUME~1\Echidna\LOCALS~1\TEMPOR~1\desktop.ini
FAILURE: C:\DOCUME~1\Echidna\LOCALS~1\TEMPOR~1\Content.IE5\index.dat

Sorry I forget to let you know - I am a local Administrator of the computer.

MacZipDocs.zip is still in the folder:
C:\Documents and Settings\Echidna\Local Settings\Temporary Internet Files

Regards,
Leigh
0
RobSampsonCommented:
Wow, that's odd!  This is my log:

Cache Files Cleared
===================
SUCCESS: C:\DOCUME~1\rsampson\LOCALS~1\TEMPOR~1\desktop.ini
SUCCESS: C:\DOCUME~1\rsampson\LOCALS~1\TEMPOR~1\Content.IE5\desktop.ini
FAILURE: C:\DOCUME~1\rsampson\LOCALS~1\TEMPOR~1\Content.IE5\index.dat
SUCCESS: C:\DOCUME~1\rsampson\LOCALS~1\TEMPOR~1\Content.IE5\08GKY8O1\MacZipDocs[1].zip
FAILURE: C:\DOCUME~1\rsampson\LOCALS~1\TEMPOR~1\Content.IE5\UJU76PAF\bb124311[1].htm

You can see it *does* delete the file...however, mine is in a subfolder....if you delete that one manually, then re-run a couple of times, does that help?

Regards,

Rob.
0
LeighWardleAuthor Commented:
Hi Rob,

Still not working...

I deleted MacZipDocs.zip from the folder:
C:\Documents and Settings\Echidna\Local Settings\Temporary Internet Files

It's still using the cached version - about 5 seconds the first time then about 0.8 seconds subsequently.


Regards,
Leigh
0
RobSampsonCommented:
That is so strange.  It has worked for me at home as well, taken 9 seconds to download it with boolClearCache set to True, and 2.5 with it at False.

Can you try on another PC?

Regards,

Rob.
0
LeighWardleAuthor Commented:
Hi Rob,

I tried it on 2 other PCs - it worked on both of them.

Regards,
Leigh
0
RobSampsonCommented:
Really?  Wow, that's strange.  I wonder if, after you download the file, you run this command:
dir /s /b "%userprofile%\locals~1\tempor~1" > TIF.txt

and then search through TIF.txt for that file, does it exist?  This will at least determine whether it can see the file without specifying whether it's a hidden file or something....

Regards,

Rob.
0
LeighWardleAuthor Commented:
Hi Rob,

I still found some PCs that the delete cache code did not work on.

But I found this-

http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1102.mspx

It's only about 6 lines and it seems to work...


Regards,
Leigh
0
RobSampsonCommented:
Oh nice!  I couldn't find that! Oh well!  I have tried that though, and interestingly, that method didn't work on my PC.....so, I've combined them both, and you can see boolClearCache to True or False above each method, depending on which you want to use:

'=======================
' Download_A_File_And_Display_Time_Taken.vbs

'======== START OF CLEAR TEMPORARY INTERNET FILES CACHE BLOCK ===========
' Delete the temporary internet files
' SET boolClearCache to True to clear cache before downloading, or set it
' to False to not clear the cache

'======== METHOD 1 ==================
boolClearCache = True
If boolClearCache = True Then
      Const TEMPORARY_INTERNET_FILES = &H20&
      
      Set objShell = CreateObject("Shell.Application")
      Set objFolder = objShell.Namespace(TEMPORARY_INTERNET_FILES)
      Set objFolderItem = objFolder.Self
      strPath = objFolderItem.Path & "\*.*"
      
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      objFSO.DeleteFile(strPath)
      Set objFSO = Nothing
End If

'======== METHOD 2 ===================
boolClearCache = True
If boolClearCache = True Then
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objShell = CreateObject("WScript.Shell")
      strTempFiles = objShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Local Settings\Temporary Internet Files"
      strTempFiles = objFSO.GetFolder(strTempFiles).ShortPath
      strCacheLog = "Cache Files Cleared" & VbCrLf & "==================="
      For Each objFile In objFSO.GetFolder(strTempFiles).Files
            strFilePath = objFile.Path
            On Error Resume Next
            objFSO.DeleteFile strFilePath, True
            If Err.Number = 0 Then
                  strCacheLog = strCacheLog & VbCrLf & "SUCCESS: " & strFilePath
            Else
                  Err.Clear
                  strCacheLog = strCacheLog & VbCrLf & "FAILURE: " & strFilePath
            End If
            On Error GoTo 0
      Next      
      For Each objSubFolder In objFSO.GetFolder(strTempFiles).SubFolders
            Call RecurseSubFolders(objSubFolder)
      Next
      Set objCacheLog = objFSO.CreateTextFile("CacheDeleteLog.txt", True)
      objCacheLog.Write strCacheLog
      objCacheLog.Close
      Set objCacheLog = Nothing
      Set objFSO = Nothing
      Set objShell = Nothing
End If

'======== END OF CLEAR TEMPORARY INTERNET FILES CACHE BLOCK ===========

strURL = "http://www.haase-online.de/dirk/maczip/download/MacZipDocs.zip"
strLocalFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & Mid(strURL, InStrRev(strURL, "/") + 1)

dteStart = Timer

' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

objXMLHTTP.open "GET", strURL, False
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
      Set objADOStream = CreateObject("ADODB.Stream")
      objADOStream.Open
      objADOStream.Type = 1 'adTypeBinary
     
      objADOStream.Write objXMLHTTP.ResponseBody
      objADOStream.Position = 0    'Set the stream position to the start
     
      Set objFSO = Createobject("Scripting.FileSystemObject")
      If objFSO.Fileexists(strLocalFile) Then objFSO.DeleteFile strLocalFile
      Set objFSO = Nothing
     
      objADOStream.SaveToFile strLocalFile
      objADOStream.Close
      Set objADOStream = Nothing
End If

Set objXMLHTTP = Nothing

dteEnd = Timer

MsgBox "Download complete." & VbCrLf & _
      "Source: " & strURL & VbCrLf & _
      "Target: " & strLocalFile & VbCrLf & _
      "Time taken: " & dteEnd - dteStart & " seconds."
     
Sub RecurseSubFolders(objFolder)
      For Each objFile In objFolder.Files
            strFilePath = objFile.Path
            On Error Resume Next
            objFSO.DeleteFile strFilePath, True
            If Err.Number = 0 Then
                  strCacheLog = strCacheLog & VbCrLf & "SUCCESS: " & strFilePath
            Else
                  Err.Clear
                  strCacheLog = strCacheLog & VbCrLf & "FAILURE: " & strFilePath
            End If
            On Error GoTo 0
      Next

      For Each objSubFolder In objFolder.SubFolders
            Call RecurseSubFolders(objSubFolder)
      Next
End Sub
'=======================

Regards,

Rob.
0
LeighWardleAuthor Commented:
Hi Rob,

I too just discovered that the Microsoft "Script Guy" code doesn't work!!

It's all too hard for me...

Thanks again for your efforts.

Cheers,
Leigh
0
RobSampsonCommented:
Hmmm, I'm sorry we couldn't get this working on some of your computers....there must be some permissions issues or something, but it could be too difficult to track down!

Sorry about that.

Regards,

Rob.
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.