agree with Leew.
however if you are using a VBS file for logon script. Then below is a sample logon script with recording logon time at the beginning. You could create similar for logoff, and apply them via GPO.
' VBScript.' Andrew Davis October 2006.
' http://www.ntbm.com.au
' ******************************
' The next line creates the Shell or environment for the commands - do not alter
Set WshShell = WScript.CreateObject("WScript.Shell")
'WScript.Echo "Starting Script!"
' The section sets the variables. Note the pattern variable = value
' You may change the variable names if you wish to check your understanding.
Set NTBMNet = WScript.CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
Set CheckDrive = NTBMNet.EnumNetworkDrives()
on error resume next
'---------------------- Record Logon attempt ------------------------------------
'DIM fso, NTBMFile, NTBMNet, strUser
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set NTBMNet = WScript.CreateObject("WScript.Network")
strUser =NTBMNet.UserName
'on error resume next
'WScript.Echo "Starting Script!"
' You will need to change this line to reflect the file that you want to store the info in.
Set NTBMFile = fso.OpenTextFile("c:\logon.csv", 8, True)
NTBMFile.Write((Date) & " , ")
NTBMFile.Write((Time) & " , ")
NTBMFile.Writeline (struser &" , Logged ON")
NTBMFile.Close
'---------------------- S Drive ---------------------------------------------
' Be very carefull with the DriveLetter, the value must be a CAPITAL letter
DriveLetter = "S:"
' You must change the VALUE \\andrew\home, unless you have a server called andrew
RemotePath = "\\{Sever}\{share}"
' This section deals with a For ... Next loop
AlreadyConnected = False
For i = 0 To CheckDrive.Count - 1 Step 2
If CheckDrive.Item(i) = DriveLetter Then AlreadyConnected = True
Next
' This section uses the If = then, else logic
' This section tests to see if the Drive is already mapped, and if yes then to disconnect
' WshShell.PopUp is not strictly necessary
If AlreadyConnected = True then
NTBMNet.RemoveNetworkDrive DriveLetter
NTBMNet.MapNetworkDrive DriveLetter, RemotePath
'WshShell.PopUp "Drive " & DriveLetter & "Disconnected, then connected successfully."
Else
NTBMNet.MapNetworkDrive DriveLetter, RemotePath
'WshShell.PopUp "Drive " & DriveLetter & " connected successfully."
End if
'-----------------------Printer Mapping----------------------------------------
Set objWSHNetwork = CreateObject("WScript.Network")
strConnectString = "\\{server}\{PrinterName1}"
strResult = objWSHNetwork.AddWindowsPrinterConnection(strConnectString)
strConnectString = "\\{server}\{PrinterName2}"
strResult = objWSHNetwork.AddWindowsPrinterConnection(strConnectString)
'---------------------- H Drive ---------------------------------------------
'this section looks at the server and if there is a folder for the user then it links them to it.
'If the folder doesnt exist then it creates it and links them.
Dim objNetwork, objFSO
Dim strDriveLetter, strUNCPath, strUser
'WScript.Echo "Starting H Drive Mapping!"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork= CreateObject("Wscript.Network")
strUser =objNetwork.UserName
strUNCPath = "\\{servername}\{Share}"
'WScript.Echo "Checking for "&STRuncpath &"\"& struser
if objFSO.FolderExists(strUNCPath) then
' WScript.Echo strUNCPath & " exists!"
if objFSO.FolderExists(strUNCPath & "\" & strUser) then
' WScript.Echo strUNCPath & "\" & strUser & " exists!"
else
' WScript.Echo "I need to create the folder"
objFSO.CreateFolder(strUNCPath & "\" & strUser)
end if
end if
objFSO.CreateFolder(strUNCPath & "\" & strUser)
strDriveLetter = "H:"
objNetwork.RemoveNetworkDrive strDriveLetter, True
objNetwork.MapNetworkDrive strDriveLetter,strUNCPath & "\" & strUser
'---------------------- REgistry Entries ---------------------------------------------
'Add Office Workgroup Template directory
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\General\SharedTemplates", "{ location eg. c:\TEMPLATES\}", "REG_EXPAND_SZ"
'Add shared Favourites dir for Internet Explorer
objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Favorites", "\\{Server}\Users\Favorites", "REG_SZ"
objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Favorites", "\\{Server}\Users\Favorites", "REG_EXPAND_SZ"
' Andrew's Script ends here
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108:





by: leewPosted on 2009-03-01 at 23:08:05ID: 23772063
Can't tell you the last login time, but you can know the last logout time by checking the date/time stamp on the user's ntuser.dat in their profile.
But really, a log would be better. Either enable auditing of logon/logoff events or create/modify a logon script that notes the logon/logout times using Group Policy.
A line in a script could be as simple as :
echo LOGON %username% %date% %time%>>LogonLogoff.log
and
echo LOGOFF %username% %date% %time%>>LogonLogoff.log
or use variations - like create a file for each person - you can then list the persons by name or by last modified time and get the last logoff time and open to get the last logon time.
for example:
echo LOGON %date% %time%>>%username%.log
and
echo LOGOFF %date% %time%>>%username%.log