Jerold
Wed Jan 25 08:59:23 CST 2006
Here is a possibility:
1. In a logon script create \\PDC\NETLOGON\%ComputerName%.%UserName%
2. In a logoff script delete \\PDC\NETLOGON\%$ComputerName%.%UserName%
When you want to determine a long a user has been logged on for, find \\PDC\NETLOGON\%ComputerName%.%UserName%
and cacl the time from NOW till the create of the above file.
On Wed, 25 Jan 2006 04:58:03 -0800, "Drew" <Drew@discussions.microsoft.com> wrote:
>I was hoping there was a script that I could run against a machine, similiar
>to the machine uptime script, where it would reply how long the currently
>logged on user, on that machine, has been logged on for....Last logon
>attribute will not help me here
>
>"Richard Mueller" wrote:
>
>> Drew wrote:
>>
>> >I have the following code which can determine the Machine uptime below
>> >
>> > I would like some code which can determine the time a user has been logged
>> > in without logging off. Almost like a User uptime script.
>> >
>> > Can anyone help me?
>> >
>> > strComputer = *.*
>> > Set objWMIService = GetObject _
>> > ("winmgmts:\\" & strComputer & "\root\cimv2")
>> > Set colOperatingSystems = objWMIService.ExecQuery _
>> > ("Select * from Win32_OperatingSystem")
>> > For Each objOS in colOperatingSystems
>> > dtmBootup = objOS.LastBootUpTime
>> > dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
>> > dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now)
>> > if dtmSystemUptime > 90000 Then
>> > wscript.echo "Unable to connect. The machine may not exist or is otherwise
>> > unavailable"
>> > wscript.quit
>> > Else
>> > Wscript.Echo dtmSystemUptime & " " & "Hours"
>> > End IF
>> > Next
>> > Function WMIDateStringToDate(dtmBootup)
>> > WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
>> > Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
>> > & " " & Mid (dtmBootup, 9, 2) & ":" & _
>> > Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _
>> > 13, 2))
>> > End Function
>>
>> Hi,
>>
>> When a user logs in, unless the user has bad password attempts, the only
>> attribute of the user object that is updated is lastLogon, and only on the
>> Domain Controller where the user authenticated(the attribute value is not
>> replicated). Active Directory has no information about which computer the
>> user is logged into, or whether the user is still logged in.
>>
>> If it helps, I have a VBScript program that retrieves the lastLogon dates
>> for all users in the domain linked here:
>>
>>
http://www.rlmueller.net/Last%20Logon.htm
>>
>> Also, it is sometimes possible to tell who is connected to a server, and for
>> how long they have maintained a session. I must caution that these sessions
>> are fleeting - they tend to come and go depending on activity. Also, they
>> are specific to a server. Here is code that displays information about
>> sessions on a specific server:
>>
>> Option Explicit
>> Dim objDC, objSession
>>
>> Set objDC = GetObject("WinNT://MyDomain/MyServer/LanmanServer")
>>
>> For Each objSession In objDC.Sessions
>> Wscript.Echo "Session: " & objSession.Name _
>> & vbCrLf & " User: " & objSession.User _
>> & vbCrLf & " Computer: " & objSession.Computer _
>> & vbCrLf & " Connect Time: " & objSession.ConnectTime _
>> & vbCrLf & " Idle Time: " & objSession.IdleTime
>> Next
>>
>> Set objSession = Nothing
>> Set objDC = Nothing
>> Wscript.Echo "Done"
>>
>> --
>> Richard
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab -
http://www.rlmueller.net
>>
>>
>>
>>
Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com