Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Log Total Logon Time

Posted on 2008-10-29
3
Medium Priority
?
223 Views
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.
0
Comment
Question by:jdana
3 Comments
 
LVL 13

Accepted Solution

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

Time
Date
User
NetBIOS Name
OU & Domain
Make/Model
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
Next
For Each objComputer in colSettingsBios
  strSerial = objComputer.SerialNumber
Next
'INSERT LOG FILE PATH HERE
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
Do
Err.Clear
Set fLogFile = oFSO.OpenTextFile(sLogFilePath, ForAppending, True)
If Err.Number <> 0 Then
WScript.Sleep 500
Else
fLogFile.WriteLine sLogLine
fLogFile.Close
bUpdLogFinished = True
End If
iLoops = iLoops + 1
Loop Until bUpdLogFinished Or iLoops > 10
On Error Goto 0
End If

Open in new window

0
 
LVL 26

Assisted Solution

by:Farhan Kazi
Farhan Kazi earned 500 total points
ID: 22833602
Have a look at following link:
http://www.rlmueller.net/Logon5.htm

Hope this helps!
Farhan
0
 

Author Closing Comment

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

885 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