VBScript program to document the logonHours property of a user. This property defines the hours in the week that the user is allowed to logon in the domain. The Distinguished Name of the user is passed to the program as a parameter. The program is designed to be run at a command prompt using the cscript host. For example:

cscript //nologo LogonHours.vbs "cn=TestUser,ou=Sales,dc=MyDomain,dc=com"

The LogonHours attribute has syntax OctetString. This is data type "Byte Array", but is really a byte string. The program first converts the string of bytes to an array of 21 bytes, and then into an array of 168 bits. There is one bit for each hour in the week. A bit with value zero means the user is not allowed to logon for that hour. A bit with value one means the user is allowed to logon. The array is offset by the time zone bias (in hours) stored in the machine registry. This bias is the offset from UTC (Coordinated Universal Time) for the time zone set in the computer. The LogonHours property is stored in Active Directory in UTC, so the program converts the hours to local time for the computer. The time zone bias read from the local registry is adjusted by the operating system for daylight savings time, so the settings remain the same all year in local time. However, the allowed logon hours will be different in different time zones.

The program outputs a header line, and then one line of zeros and ones for each day of the week. A zero means the user is not allowed to logon during the corresponding hour. A one means the user can logon.

If the Distinguished Name passed to the program has a character that must be escaped, such as a comma, be sure to escape the character with the backslash escape character, "\". The characters that must be escaped are:

, \ / # + < > ; " =

For example, the command to document logon hours for "cn=Wilson, Jane" might be:

cscript //nologo LogonHours.vbs "cn=Wilson\, Jane,ou=West,dc=MyDomain,dc=com"

This program should work on any 32 or 64-bit Windows client that can log onto the domain. Windows NT and Windows 98/95 clients should have DSClient installed. If DSClient is not installed, they need WSH and ADSI installed.

LogonHours.txt <<-- Click here to view or download the program

An equivalent PowerShell script is linked below.

PSLogonHours.txt <<-- Click here to view or download the program