Track Logon’s and Logoff’s

A couple of days ago I get a request from my pal Harry of SMB Nation fame to answer a request from a reader of SMB Partner Community Magazine, of course I said I would do what I could.

Turns out the reader was looking for a way to track when folks logged on and off their computers. Boy did I luck out on this one, just so happens I had to solve this for a client a couple of years ago.

Here is what I did, maybe it can help you also,

First we need to create a share on the server lets call it Logging and lets give everybody write access to it. Make sure the system, the adminsitrator and the company owner has full access to it.

Next lets create a couple of batch files

Note: remove ” on the lines that follow, everything between the quotes is on one line

One we will call “LogOnWhen.cmd”

it will contain one line

“echo %COMPUTERNAME%,%USERNAME%,LogOn,%DATE%,%TIME% >> \\ServerName\Logging\%USERNAME%.csv

The other one we will call “LogOffWhen.cmd”

and it will aslo contain one line

“echo %COMPUTERNAME%,%USERNAME%,LogOff,%DATE%,%TIME% >> \\ServerName\Logging\%USERNAME%.csv

Make sure to replace ServerName with the actual name of your server in both lines!

Next create a group policy object or GPO in the advanced section of the SBS Console.

Expand the advanced section and in the GPMC

Here is what it should look like, I called mine Record Logon Logoff, it is always a good idea to use a descriptive name so you remember what it does later.

Record Logon Logoff

Once you are happy with your GPO right click on the SBSusers OU and link your new GPO to it.

Make sure to copy the files we created to the directories created in the new GPO

You can find out the QniqueID of your gpo by looking at the Details Tab

Unique ID

Once you know the ID look in the sysvol directory to locate your GPO

Put Files Here

Expand the folder for your GPO and put each file in it’s respective directory.

Now you can either reboot your server or run the command “gpupdate /force” from the command line

Now whenever anyone logs on or off their cvs file in the logging directory will be updated.

Originally we had all the info going into the same file, but it turned out to be easier to deal with, having a seperate file for each user.

I did take it one step further and create an Excel Workbook with 1 sheet for each user,  their sheet is linked to the cvs file so the owner can open one file and see whatever he is looking for.

I am sorry but I can not show you the spreadsheets as they contain private info.

Leave a Reply