| |
mbouchard
Posts: 1804
Score: 12
Joined: 5/15/2003
From: USA
Status: online
|
I am posting this in response to another post. This is a sub that I use in many of my scripts, it will create the log file if it is not already present, it will then open the file and append to it whenever the sub is called. 'Do something here Call WriteToLog("Some Info Here") 'Do something else here Sub WriteToLog(Message) ' For writing description of installation to Software Configuration.log Const FORREADING = 1 Const FORWRITING = 2 Const FORAPPENDING = 8 Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject") Dim fLog, strLogFile, strLogFileLoc strLogFile = "Name of Some Log Here" ' ex. Software Configuration strLogFileLoc = "c:\program files\" & strLogFile & ".log" ' Create the log file if it does not exist If not Fso.FileExists(strLogFileLoc) Then Set fLog = Fso.CreateTextFile(strLogFileLoc, True) fLog.WriteLine(strLogFile & " Log")' i.e. Software Configuration Log fLog.Close End If ' Append to the log file Set fLog = Fso.OpenTextFile(strLogFileLoc, FORAPPENDING) If Message = "" Then fLog.WriteLine("") flog.Close Else 'Writes the message to the log file, prefixed by the Date/Time fLog.WriteLine(Now & " " & Message) fLog.Close End If End Sub fLog.WriteLine(Now & " " & Message) fLog.Close End If End Sub
_____________________________
Mike For useful Scripting links see the Read Me First stickey! Always remember Search is your friend.
|
|