I had to solve this problem for doing remote support throughout my company. Things like PsLoggedOn, and tools to scan the domain controller's security logs proved to be far too slow for my purposes (getting the hostname to do remote support for users). Here's what I came up with:
- All users have an drive mapped to X: in AD under Profile - Home folder
- Everyone has the below script assigned under Profile - Logon script
This script records what computer they logged into in their home folder. It specifically doesn't record them logging into our terminal server, because I don't care about such entries.
'===============================================================
' Record the logon in their X: drive UNLESS they are on TERM-SERVER!
'===============================================================
If strComputerName <> "TERM-SRVER" Then
strFile = "X:\login.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strFile, 8, True)
objTextFile.WriteLine(strIP + " - " + strComputerName + " - " + CStr(Date) + " " + CStr(Time))
objTextFile.Close
' Make it hidden
Set objTextFile = objFSO.GetFile(strFile)
objTextFile.Attributes = 2
End If
Then I use a bit of VBscript on my local machine to automatically find their home directory in AD, open the log file, and print out the last few lines.