Record user logon and off date and times into a database

Posted on 2009-04-07
Last Modified: 2012-05-06
Hi all.

Wondering if the above is posible. and if so how???

We have been using Group Policy to  log all users logon's and logoff's on our network.

This is only recording it into a txt file or csv file.  This really is not helping with a automated preview as the data is inserted differently. i,e, some PC's insert Logoff Username PCName Day Date Time, where as other only put in Logoff Username PCName Date Time (Leaving of the day) which i can nto automate...

I was wondering if there is anyway i can record this information without having to import it into a database.

I was wondering either Access or SQL. I was thinking along the lines of SQLCMD, but as far as i can see, unless i have it installed on every PC, it will not work.

Does any have any suggestions??

------So far----

rem ------logon.cmd----

echo logon %username% %computername% %date% %time% >> \\postmaster2\log\logon.log

echo logon %username% %computername% %date% %time% >> \\postmaster2\log\log_on.csv

rem -----logoff.cmd-----

echo logoff %username% %computername% %date% %time% >> \\postmaster2\log\logoff.log

echo logoff %username% %computername% %date% %time% >> \\postmaster2\log\log_off.csv

Open in new window

Question by:Bakersville
  • 2
  • 2

Expert Comment

Comment Utility
Just to be sure, did you know that there is a built in auditing ability in Windows?  

Author Comment

Comment Utility
Thank you for that.

My issue is that i have to try and find the amount of time they are spending on their PC, so need to be able to pull this information into somewhere i can automaticlly generate reports.

This is why i was wondering if something like sqlcmd is worth a shot?

Accepted Solution

brittonv earned 500 total points
Comment Utility
To be honest I don't know if you can do it with sqlcmd.

Here is a script that shows the last logon.  Perhaps you could use a script that calculates the time logged on and puts that in your text file instead.
'<script language="vbscript">


DIM oNet, strComputerName, strUserName, strUserDomain

SET oNet = CreateObject("WScript.Network")

strComputerName = oNet.Computername

strUserName = oNet.UserName

strUserDomain = oNet.UserDomain

'msgbox strUserDomain

SET oNet = nothing

DIM oUser, strReturn

on error resume next

SET oUser = GetObject("WinNT://" & fnGetWorkgroupName(".") & "/" & strComputerName & "/" & strUserName & ",user")

strReturn = oUser.LastLogin

on error goto 0

SET oUser = nothing

IF isDate(strReturn) THEN

	strReturn = cdate(strReturn)

	strReturn = Replace(strReturn, ":" & Right(0 & Second(strReturn), 2) & " ", "")	'drop seconds


On Error Resume Next

	call WScript.Echo(strReturn)	'for cmd line

	call Echo(strReturn)	'for BGInfo

on error goto 0

' gets current workgroup

' params: computer name (can take "." for current computer instead)

' returns: string of computer's current workgroup

FUNCTION fnGetWorkgroupName(p_strComputer)

	DIM colItems, oItem

	Set colItems = GetObject("winmgmts:\\" & p_strComputer & "\root\cimv2").ExecQuery("Select * from Win32_ComputerSystem",,48)

	For Each oItem in colItems

		fnGetWorkgroupName = oItem.Domain


	SET colItems = nothing


Open in new window


Author Closing Comment

Comment Utility
Thank you, this pointed me in the right firection

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now