' Logoff5.vbs ' VBScript Logoff script. ' This program demonstrates how to log information to a log file. ' ' ---------------------------------------------------------------------- ' Copyright (c) 2009-2010 Richard L. Mueller ' Hilltop Lab web site - http://www.rlmueller.net ' Version 1.0 - May 5, 2009 ' Version 1.1 - June 10, 2010 - Delimit log file with ";". ' Version 1.2 - November 6, 2010 - No need to set objects to Nothing. ' ' You have a royalty-free right to use, modify, reproduce, and ' distribute this script file in any way you find useful, provided that ' you agree that the copyright owner above has no warranty, obligations, ' or liability for such use. Option Explicit Dim objFSO, objLogFile, objNetwork, objShell, strText, intAns Dim intConstants, intTimeout, strTitle, intCount, blnLog Dim strUserName, strComputerName, strShare, strLogFile strShare = "\\MyServer\LogFile" strLogFile = "Domain.log" intTimeout = 20 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = CreateObject("Wscript.Network") Set objShell = CreateObject("Wscript.Shell") strUserName = objNetwork.UserName strComputerName = objNetwork.ComputerName ' Log date/time, user name, and computer name. If (objFSO.FolderExists(strShare) = True) Then On Error Resume Next Set objLogFile = objFSO.OpenTextFile(strShare & "\" _ & strLogFile, 8, True, 0) If (Err.Number = 0) Then ' Make three attempts to write to log file. intCount = 1 blnLog = False Do Until intCount = 3 objLogFile.WriteLine "Logoff;" & Now & ";" _ & strComputerName & ";" & strUserName If (Err.Number = 0) Then intCount = 3 blnLog = True Else Err.Clear intCount = intCount + 1 If (Wscript.Version > 5) Then Wscript.Sleep 200 End If End If Loop On Error GoTo 0 If (blnLog = False) Then strTitle = "Logon Error" strText = "Log cannot be written." strText = strText & vbCrlf _ & "Another process may have log file open." intConstants = vbOKOnly + vbExclamation intAns = objShell.Popup(strText, intTimeout, strTitle, _ intConstants) End If objLogFile.Close Else On Error GoTo 0 strTitle = "Logon Error" strText = "Log cannot be written." strText = strText & vbCrLf & "User may not have permissions," strText = strText & vbCrLf & "or log folder may not be shared." intConstants = vbOKOnly + vbExclamation intAns = objShell.Popup(strText, intTimeout, strTitle, intConstants) End If End If