We help IT Professionals succeed at work.

Retrieving User Login Hours With ADSI

markcfellows
markcfellows asked
on
How can the information retrieved from the LoginHours property be converted into meaningful data. At present the property is returning spurious characters e.g.?????????

According to Microsoft documentation the property description is as follow:

"Time periods for each day of the week during which logons are permitted for the user. Represented as a table of Booleans for the week, each indicating if that time slot is a valid logon time."
Comment
Watch Question

Commented:
Dim User
Dim UserName
Dim UserDomain
Dim TimeEntry
Dim Restriction
UserDomain = "Target_User_Domain"
UserName = "Target_User_Name"
Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user")
For Each TimeEntry In User.LoginHours
    If TimeEntry < 255 Then Restriction = 1
Next
If Restriction = 1 Then
    Response.Write "User account " & UserDomain & "\" & UserName & " has time restrictions placed upon it."
Else
    Response.Write "There are no time restrictions affecting user account " & UserDomain & "\" & UserName & "."
End If

Author

Commented:
Thanks, this does help me. However I need to find each users exact login hours.

Author

Commented:
I have had a quick look and I can get the information I need with the help of your code.

Thanks again for your help.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.