Logging the user logons….

265 pts.
Microsoft Windows
SQL Server
Hi, Is there a way to log the users logons(date and time)on every computers from the server or my computer?is there any policy or command or scrip for doing it? Thank you so much. -------- Regards Mahnaz

Answer Wiki

Thanks. We'll let you know when a new response is added.

I think the next script is what you are looking
The script is for logon only. For logoff wou must change “Logon” with “Logoff”

‘* Script Name: logon.vbs
‘* Author: Ciprian Ionut Lozonschi
‘* Created on: 26.11.2003
‘* Description: record into a dastabase (SQL Server) users logons
‘* History:
‘* Operating System (Supported Platforms): XP, 2k3
‘* URL:

‘On Error Resume Next
Set objNet = WScript.CreateObject(“WScript.Network”)

‘connect to MS SQL Server
Set oConn= WScript.CreateObject(“ADODB.Connection”)
oConn.Open = “Provider = SQLOLEDB.1; Password = password;” & _
“Persist Security Info = True; User ID = userid;” & _
“Initial Catalog = DBName; Data Source = DBServerName;” & _
“Network Library = dbmssocn”

‘Password = SQL user password
‘User ID = SQL user id
‘Initial Catalog = SQL database name
‘Data Source = SQL Server name or IP

sqlIns = “insert into LogUsers (TipConexiune, UserName, ComputerName) values (‘Logon’, ‘” & objNet.UserName & _
“‘,'” & objNet.ComputerName & “‘)”
oConn.Execute = sqlIns


For the script to work you must have a database, in my case is a MS SQL DB Server (you could also record this in a access database, but you must change string connection – oConn) with a table, in my case named LogUsers with 4 fields: TipConexiune, UserName, ComputerName, Date (type Date with default value “getdate()”).

The script you must put to execute when a user logon (Group Policy – User ConfigurationWindows Settings – Logon)

Discuss This Question: 4  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Tracybs
    What you are looking for is the Audit Policy, Audit Account Logon Events. You can create this policy on the DC and then push it out to all your workstations. If your workstations aren?t all part of the same domain then you?ll have to activate this on each workstation. And I?ll bet that with Windows Scripting Host you can pull the audit logs from each machine remotely, even set up a batch job to pull them every night, week, month, etc.
    0 pointsBadges:
  • Markf5
    Here is a link that describes auditing on server. http://techrepublic.com.com/5100-6350-6028421.html
    0 pointsBadges:
  • AndyPaul
    Here is sample script I run again my Active Directory to determine last login of my users. It writes to a local access db file... but you can modify it to output to other formats (txt, xl, SQL, etc.). Hope it helps. Const ADS_SCOPE_SUBTREE = 2 on error resume next Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection objCommand.Properties("Page Size") = 1000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.CommandText = _ "SELECT ADsPath FROM 'LDAP://ou=Users,dc=mydoman,dc=local'" Set objRecordSet = objCommand.Execute Set objConn = CreateObject("ADODB.Connection") Set objRS = CreateObject("ADODB.Recordset") objConn.Open "DSN=EventLogs;" objRS.CursorLocation = 3 objRS.Open "SELECT * FROM Users" , objConn, 3, 3 objRecordSet.MoveFirst Do Until objRecordSet.EOF 'objRecordSet.Fields("ADsPath").Value Set objOU = GetObject (objRecordSet.Fields("ADsPath").Value) ObjOU.Filter= Array("user") For Each objUser in objOU objRS.AddNew objRS("OU") = objRecordSet.Fields("ADsPath").Value objRS("User") = objuser.sAMAccountName objRS("FullName") = objuser.cn objRS("LastLogon") = objuser.lastlogin ' objRS("LastLogoff") = objuser.lastlogoff objRS.Update Next objRecordSet.MoveNext Loop objRS.Close objConn.Close Wscript.Echo "User Scan Complete"
    0 pointsBadges:
  • Tring17
    This is what I use. http://msmvps.com/blogs/kwsupport/archive/2005/02/24/36942.aspx
    0 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: