I know to use event viewer to check who logged into the system and when. But I am trying to figure out for a particular local user account, say administrator - what all are the login date and time for this particular user in that machine. I use this script and it says me total counts of logon, but not when all. The script is given below.
'Get our list of logons
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkLoginProfile",,48)
'Converts to a readable logon date and time function ConvertTime(sTime)
if (sTime="**************.******+***") then
ConvertTime = "Unknown"
else
if (Trim(sTime)="") then
sTime="Unknown"
else
sYear = Mid(sTime,1,4)
sMonth = Mid(sTime,5,2)
sDay = Mid(sTime,7,2)
sHour = Mid(sTime,9,2)
sMin = Mid(sTime,11,2)
sSec = Mid(sTime,13,2)
end if
ConvertTime = sMonth & "/" & sDay & "/" & sYear & " (" & sHour & ":" & sMin & ":" & sSec & ")"
end if
end function
'Loops through our logon items and only pulls out the
'user accounts...not system accounts that are used
'internally by windows
For Each objItem in colItems
if (objItem.UserType = "Normal Account") then
Wscript.Echo objItem.Name & vbCrLf
Wscript.Echo " Last Logon: " & ConvertTime(objItem.LastLogon)
Wscript.Echo " Number of Logons: " & objItem.NumberOfLogons
if (objItem.Privileges=0) then
WScript.Echo " (Guest Account)"
else if (objItem.Privileges=1) then
WScript.Echo " (Standard User Account)"
else if (objItem.Privileges=2) then
WScript.Echo " (Administrator Account)"
end if
end if
end if
WScript.Echo vbCrLf
end if
Next
Edited to show expected output
Username: LocalPC\Administrator
Logon time: ------
Username: LocalPC\Administrator
Logon time: ------
Can someone please tell me how can I modify this script or is there any other method to check the same in an easiest way asap.? Thanks in advance.