Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for login_log_access.vbs

(view source code of login_log_access.vbs as plain text)

  1. Const ForAppending  = 8
  2. Const TristateFalse = 0
  3. ' Get today's date in YYYYMMDD format and time in HHmmss format
  4. strToday = CStr( 10000 * Year( Now ) + 100 * Month( Now ) + Day( Now ) )
  5. lngNow   = 1000000 + 10000 * Hour( Now ) + 100 * Minute( Now ) + Second( Now )
  6. strNow   = Right( CStr( lngNow ), 6 )
  7. ' Get the current user and computer names
  8. Set wshNetwork = CreateObject( "WScript.Network" )
  9. strUser     = wshNetwork.UserName
  10. strComputer = wshNetwork.ComputerName
  11. Set wshNetwork = Nothing
  12. ' Create the directory if it doesn't exist
  13. Set objFSO = CreateObject( "Scripting.FileSystemObject" )
  14. With objFSO
  15. 	strFolder = .BuildPath( "\\Server\Logs", strToday )
  16. 	If Not .FolderExists( strFolder ) Then
  17. 		.CreateFolder strFolder
  18. 	End If
  19. 	strLog = .BuildPath( strFolder, strUser & ".log" )
  20. 	Set objLog = .OpenTextFile( strLog, ForAppending, True, TristateFalse )
  21. 	objLog.WriteLine strComputer & "," & strToday & "," & strNow
  22. 	objLog.Close
  23. 	Set objLog = Nothing
  24. End With
  25. Set objFSO = Nothing

page last uploaded: 2021-01-27