Get login time for a user

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hi,

Does anyone has any script to get login time for a user on a windows machine?

Thanks in advance.
 
The system creates a security event log 540. You can modify the followng
script to read the security event logs

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("Select * from Win32_NTLogEvent Where Logfile = 'Security' and " _
& "EventCode = '540'")
For Each objEvent in colLoggedEvents
strTimeWritten = objEvent.TimeWritten

dtmTimeWritten = CDate(Mid(strTimeWritten, 5, 2) & "/" & _
Mid(strTimeWritten, 7, 2) & "/" & Left(strTimeWritten, 4) _
& " " & Mid (strTimeWritten, 9, 2) & ":" & _
Mid(strTimeWritten, 11, 2) & ":" & Mid(strTimeWritten, 13,
2))

dtmDate = FormatDateTime(dtmTimeWritten, vbShortDate)
dtmTime = FormatDateTime(dtmTimeWritten, vbLongTime)

Wscript.Echo "Username: " & objEvent.User
WScript.Echo "Date: " & dtmDate
WScript.Echo "Time: " & dtmTime
Next
 
David said:
Hi,

Does anyone has any script to get login time for a user on a windows
machine?

Thanks in advance.

Is he part of a network? If so, you can find out from the event logs on the
server.

SC Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top