Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Log Total Logon Time

Posted on 2008-10-29
Medium Priority
Last Modified: 2010-04-21
I worked out a deal with my boys where they need to give me an hour of reading for every hour of computer game time.  I'm running Windows Server 2003 at home, and both boys have a domain account.  Is there a Group Policy, a domain account property, or a script  that enables me to log their time logged on?  Ideally, I'd like to push the data into SQL Server (where I keep everything else), but a simple log file will work fine as well.
Question by:jdana
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 13

Accepted Solution

Brum07 earned 500 total points
ID: 22833506
You could run a logon and then log off script (as below) this records the following

NetBIOS Name
OU & Domain
Serial Number

You could then calculate from the two times how long a user was on the system

Dim objWMI : Set objWMI = GetObject("winmgmts:")
Dim colSettingsComp : Set colSettings = objWMI.ExecQuery("Select * from Win32_ComputerSystem")
Dim colSettingsBios : Set colSettingsBios = objWMI.ExecQuery("Select * from Win32_BIOS")
Dim objComputer, strModel, strSerial
For Each objComputer in colSettings
  strModel = objComputer.Model
For Each objComputer in colSettingsBios
  strSerial = objComputer.SerialNumber
sLogFilePath = "C:\log.csv"
sType = "Logon"
Const OpenAsASCII = 0
Const OverwriteIfExist = -1
Const ForAppending = 8
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWshNetwork = CreateObject("WScript.Network")
Set oADSystemInfo = CreateObject("ADSystemInfo")
sDate = date
sTime = time
sComputer = oWshNetwork.ComputerName
sUser = oWshNetwork.UserName
Set oUser = GetObject("LDAP://" & oADSystemInfo.UserName)
sUserOU = Mid(oUser.Parent, 8)
sLogLine = """" & sType & """,""" & sDate & """,""" & sTime & """,""" & sUser _
& """,""" & sComputer & """,""" & sUserOU & """,""" & strModel & """,""" & strSerial & """"
If oFSO.FolderExists(oFSO.GetParentFolderName(sLogFilePath)) Then
bUpdLogFinished = False
iLoops = 0
On Error Resume Next
Set fLogFile = oFSO.OpenTextFile(sLogFilePath, ForAppending, True)
If Err.Number <> 0 Then
WScript.Sleep 500
fLogFile.WriteLine sLogLine
bUpdLogFinished = True
End If
iLoops = iLoops + 1
Loop Until bUpdLogFinished Or iLoops > 10
On Error Goto 0
End If

Open in new window

LVL 26

Assisted Solution

by:Farhan Kazi
Farhan Kazi earned 500 total points
ID: 22833602
Have a look at following link:

Hope this helps!

Author Closing Comment

ID: 31511287
Thanks guys.  These are perfect!  Maybe I'll customize the scripts a little and practice my VBS skills (which stink).

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

718 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