' ============================================================================ ' Common purpose VBScript classes - CLog class ' Version 1.00 (12.04.01) ' ' Copyright (c) 2001 http://scripting.narod.ru ' All rights reserved. ' ' Web: http://scripting.narod.ru/ ' e-mail: scripting@narod.ru ' ============================================================================ Option Explicit Class CLog Private m_FSO Private m_LogFullName Private m_ScriptName Private m_ScriptPath Private m_Format Private m_IncludeTime Private Sub Class_Initialize Set m_FSO = CreateObject("Scripting.FileSystemObject") m_ScriptName = WScript.ScriptName Dim I I = InStrRev(m_ScriptName, ".") If I > 0 Then m_ScriptName = Left(m_ScriptName, I - 1) m_ScriptPath = WScript.ScriptFullName I = InStrRev(m_ScriptPath, "\") If I > 0 Then m_ScriptPath = Left(m_ScriptPath, I) m_LogFullName = m_ScriptPath & m_ScriptName & ".log" m_Format = 0 ' ANSI m_IncludeTime = True End Sub Private Sub Class_Terminate Set m_FSO = Nothing End Sub Property Get FSO Set FSO = m_FSO End Property Property Let LogFullName(NewName) m_LogFullName = NewName End Property Property Get LogFullName LogFullName = m_LogFullName End Property Property Get ScriptPath ScriptPath = m_ScriptPath End Property Property Get ScriptName ScriptName = m_ScriptName End Property Property Let Format(NewFormat) m_Format = NewFormat End Property Property Get Format Format = m_Format End Property Property Let IncludeTime(NewValue) m_IncludeTime = NewValue End Property Property Get IncludeTime IncludeTime = m_IncludeTime End Property Function Write(Text) On Error Resume Next ' if access denied or any other reason Dim File Set File = m_FSO.OpenTextFile(m_LogFullName, 8, True, m_Format) Write = Err = 0 If Write Then If m_IncludeTime Then Text = Now & " " & Text File.Write Text & vbNewLine File.Close End If Set File = Nothing On Error GoTo 0 End Function Function ReadAll On Error Resume Next ' if file does not exist Dim File Set File = m_FSO.OpenTextFile(m_LogFullName, 1, False, m_Format) If Err = 0 Then ReadAll = File.ReadAll File.Close Else ReadAll = "" End If Set File = Nothing On Error GoTo 0 End Function Function Clear On Error Resume Next ' if file does not exist m_FSO.DeleteFile m_LogFullName, True Clear = Err = 0 On Error GoTo 0 End Function End Class ' ============================================================================