![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Help with VBScript Timer I need to write a script that will time the download and upload of different size files or folders to a NAS. I am trying to put together data on upload and download times from different loactions. Here is what I have so far. It download the file but never finishes the timer. Is there an easy way to do this. Thanks in Advance Dim WshShell,fso Dim LOGFILENAME Dim cnt Const ForReading = 1, ForWriting = 2, ForAppending = 8 Const FILELOGPATH = "c:\commonlog\applications\consolidated\download_timer.log" Const ERRORLOGPATH = "C:\commonlog\applications\consolidated\download_timer_error.log" '----------------------------- 'CREATE OBJECTS FOR LATER USE '----------------------------- Set WshShell = WScript.CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") Set evar = wshshell.environment("Process") Set WshNet = WScript.CreateObject("WScript.Network") 'To keep script from failing on error 'On Error Resume Next '--------------------------- 'Main '--------------------------- Dim conn,conStr,conSoft,strSQL,rs,StartTime,c 'Open error log Set ErrorLog = fso.OpenTextFile(ERRORLOGPATH,ForAppending,True) StartTime = Timer '------------------------ fso.CopyFolder "\\<servername>\<sharename>\<folder>", "c:\temp\" '------------------------ If Err <>0 Then msg = "An error occurred while trying to create the recordset:" & Err & vbCrLf 'Create an understandable error msg msg = msg & "Error number: " & Err & vbCrLf msg = msg & "Description: " & Err.Description Wscript.Echo msg WshShell.Popup msg,3, "Error Pulling Records!",64 ErrorLog.writeline "<ScriptName>: " & Err.Description & " " & Now() & " " & FormatNumber(Timer - StartTime,2) Else wscript.echo "Recordset created successfully." ErrorLog.writeline "<ScriptName>: Completed Successfully " & Now() & " " & FormatNumber(Timer - StartTime,2) End If |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Help with VBScript Timer "Huskerboy" <Huskerboy@xxxxxx> wrote in message news:6BAC4816-933F-40FF-8732-F38CCDAA3558@xxxxxx Quote: >I need to write a script that will time the download and upload of >different > size files or folders to a NAS. > I am trying to put together data on upload and download times from > different > loactions. > Here is what I have so far. It download the file but never finishes the > timer. > Is there an easy way to do this. > > Thanks in Advance > > Dim WshShell,fso > Dim LOGFILENAME > > > > Dim cnt > > Const ForReading = 1, ForWriting = 2, ForAppending = 8 > Const FILELOGPATH = > "c:\commonlog\applications\consolidated\download_timer.log" > Const ERRORLOGPATH = > "C:\commonlog\applications\consolidated\download_timer_error.log" > '----------------------------- > 'CREATE OBJECTS FOR LATER USE > '----------------------------- > Set WshShell = WScript.CreateObject("WScript.Shell") > Set fso = CreateObject("Scripting.FileSystemObject") > Set evar = wshshell.environment("Process") > Set WshNet = WScript.CreateObject("WScript.Network") > > 'To keep script from failing on error > 'On Error Resume Next > '--------------------------- > 'Main > '--------------------------- > > > > Dim conn,conStr,conSoft,strSQL,rs,StartTime,c > 'Open error log > Set ErrorLog = fso.OpenTextFile(ERRORLOGPATH,ForAppending,True) > > StartTime = Timer > '------------------------ > > fso.CopyFolder "\\<servername>\<sharename>\<folder>", "c:\temp\" > > > > '------------------------ > > If Err <>0 Then > msg = "An error occurred while trying to create the recordset:" & Err & > vbCrLf 'Create an understandable error msg > msg = msg & "Error number: " & Err & vbCrLf > msg = msg & "Description: " & Err.Description > Wscript.Echo msg > WshShell.Popup msg,3, "Error Pulling Records!",64 > ErrorLog.writeline "<ScriptName>: " & Err.Description & " " & Now() & " " > & FormatNumber(Timer - StartTime,2) > Else > wscript.echo "Recordset created successfully." > ErrorLog.writeline "<ScriptName>: Completed Successfully " & Now() & " " & > FormatNumber(Timer - StartTime,2) > End If between the start and end times. This is the best way to time operations in VBScript. The code you included will halt if there is an error, so Err.Number will never be non-zero. Assuming no errors, the information about success should be logged. I would suggest (in part): ======= Dim EndTimer StartTime = Timer() On Error Resume Next fso.CopyFolder "\\<servername>\<sharename>\<folder>", "c:\temp\" EndTime = Timer() If (Err.Number <> 0) Then msg = "An error occurred:" & vbCrLf msg = msg & "Error number: " & Err.Number & vbCrLf msg = msg & "Description: " & Err.Description On Error GoTo 0 ErrorLog.writeline Err.Description & " " & Now() & " " & FormatNumber(EndTime - StartTime, 2) Else On Error GoTo 0 ErrorLog.writeline "Completed Successfully " & Now() & " " & FormatNumber(EndTime - StartTime,2) End If ErrorLog.Close ====== If there is an error, you don't want "On Error Resume Next" in affect or you cannot troubleshoot. I assume above that the only error worth trapping is an error on the copy statement. Your problem might even have been that you did not close the log file. In my version I restore normal error handling as soon as I can, after retrieving properties of the Err object. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| How to do No hang up VBScript (nohup for VBScript) | VB Script | |||
| Egg Timer | Vista General | |||
| RC2 Egg Timer | Vista General | |||
| Egg timer on XP | Vista General | |||
| Egg Timer | Vista General | |||