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 property has syntax OctetString. This is VB 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 zero bit means the user is not allowed to logon for that hour. A one means the user is allowed to logon. The array is offset by the Time Zone bias 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 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-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