I am attempting to create script that sends info and login/logoff timestamps to a text file. Can anyone assist with showing me how to get it to output the duration between login and logoff? AT the moment the script creates a separate line for each login and logoff. I can't seem to figure out on to get them all on one line in the text file. Any help would be appreciated.

This is the code that I have atm

ON ERROR RESUME NEXT

Dim WSHShell, WSHNetwork, ComputerString, UserNameString, DateTimeString, objConn, actionString, actionString2
Dim strDirectory, strFile, strText, objFSO, objFolder, objFile, objTextFile, result,
Dim login As DateTime =  New DateTime(2010,2,23,07,30,30)
Dim logoff As DateTime =  New DateTime(2010,2,23,10,30,30)
Dim TS As TimeSpan =  logoff - login

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")

'Get Date and Time, Workstation Name, and User Name
ComputerString = WshNetwork.ComputerName
UserNameString = WshNetwork.UserName
DateTimeString = now()
actionString = "Logon"

strDirectory = "c:\loginlog"
strFile = "\trackinglog.txt"
strText = ("{0} - {1} = {2}", login, logoff, duration)

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
   Set objFolder = objFSO.GetFolder(strDirectory)
Else
   Set objFolder = objFSO.CreateFolder(strDirectory)
End If

If objFSO.FileExists(strDirectory & strFile) Then
   Set objFolder = objFSO.GetFolder(strDirectory)
Else
   Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
End If

'Clean up Memory
set WSHShell = nothing
set WSHNetwork = nothing
set ComputerString = nothing
set UserNameString = nothing
set DateTimeString = nothing


'Quit the Script
wscript.quit

Well. When the application runs on logon, record a time on the load event. The application will close when the computer is shut down and therefore, record a time on the form closing event.

Hi
Do you have access to a Database? If so store the login records with a timestamp and when the user logs out retrieve this record and get the time difference between the stamp and current time.

If not store your logins in another file and parse it from to get the last login for the user.

This article has been dead for over six months. Start a new discussion instead.