Recording AD Logons to SQL Database
I've been trying to find a way to keep a running log of who logged on, when
and from what pc by running the code below in my login script. The code
works, but the csv file method is limited since it tends to lock up the file
if more than one is trying to write to it simultaneously. I want to do
basically the same thing, but log it directly to SQL. Any ideas?
'************************************************* ****
'** Record Logon Information
'************************************************* ****
'Check for the existance of the drop log and create new file if necessary
Const FOR_APPENDING = 8
strOutputFile = "\\servername\drop$\ad\adlog.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strOutputFile) Then
Set objTextStream = objFSO.OpenTextFile(strOutputFile, FOR_APPENDING)
Else
Set objTextStream = objFSO.CreateTextFile(strOutputFile)
End If
'get user info
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
strMessage = objUser.CN &","& objComputer.CN &","& Now &","
'write it to the file
objTextStream.WriteLine strMessage
objTextStream.Close
|