>
>
> "Richard Mueller [MVP]" wrote:
>
>>
>> > Thanks for the explanation
>> >
>> > Could you provide sample code in vb as I've converted the vbscripts
>> > that
>> > manage users into vba for use in an Access database
>> >
>> >
>>
>> Code similar to below worked for me in VB6, where you can declare byte
>> arrays. This depends on being able to code:
>>
>> Dim arrbytArray() As Byte
>>
>> This example hard codes the hours in 7 strings of 24 binary bits, for
>> each
>> hour in each day of the week.
>> ============
>> Option Explicit
>>
>> Public Sub SetLogonHrs(ByVal strUserDN As String)
>> ' Subroutine to set the logonHours attribute for selected user.
>>
>> Dim objShell As Object, lngBiasKey As Variant, lngBias As Integer
>> Dim objUser As Object, strSunHrs as String, strMonHrs as String
>> Dim strTueHrs as String, strWedHrs as String, strThuHrs as String
>> Dim strFriHrs as String, strSatHrs as String, arrbytLogonHours As
>> Variant
>>
>> ' Retrieve time zone bias from local registry.
>> Set objShell = CreateObject("Wscript.Shell")
>> lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control"
>> _
>> & "\TimeZoneInformation\Bias")
>> If UCase(TypeName(lngBiasKey)) = "LONG" Then
>> lngBias = lngBiasKey \ 60
>> End If
>> If UCase(TypeName(lngBiasKey)) = "VARIANT()" Then
>> lngBias = 0
>> For k = 0 To UBound(lngBiasKey)
>> lngBias = lngBias + (lngBiasKey(k) * 256 ^ k)
>> Next
>> lngBias = lngBias \ 60
>> End If
>>
>> ' Bind to user object.
>> Set objUser = GetObjet("LDAP://" & strUserDN)
>>
>> ' Specify logon hours, in local time.
>> ' 0 means not allowed to logon, 1 means allowed to logon.
>> ' Each string specifies the 24 hours in one day, from
>> ' 0:00 to 23:00.
>> ' 00000000011 00000000011.
>> ' M12345678901N12345678901.
>> strSunHrs = "000000000000000000000000"
>> strMonHrs = "000000011111111111100000"
>> strTueHrs = "000000011111111111110000"
>> strWedHrs = "000000011111111111111000"
>> strThuHrs = "000000011111111111110000"
>> strFriHrs = "000000011111111111100000"
>> strSatHrs = "000000000111110000000000"
>>
>> arrbytLogonHours = SetUserLogonHrs(strSunHrs, strMonHrs, strTueHrs,
>> strWedHrs, _
>> strThuHrs, strFriHrs, strSatHrs, lngBias)
>>
>> objUser.Put "logonHours", arrbytLogonHours
>> objUser.SetInfo
>>
>> End Sub
>>
>> Private Function SetUserLogonHrs(ByVal strSun As String, ByVal strMon As
>> String, _
>> ByVal strTue As String, ByVal strWed As String, ByVal strThu As
>> String, _
>> ByVal strFri As String, ByVal strSat As String, _
>> ByVal lngBias As Integer) As Variant
>> ' Function to convert the logonHours attribute of a user from seven
>> binary
>> ' strings to a byte array.
>> Dim strString As String, strHrs As String, strHex As String, strByte
>> As
>> String
>> Dim k As Integer, strStr1 As String, strStr2 As String
>>
>> ' Convert to one string of binary values (0 and 1).
>> strString = strSun & strMon & strTue & strWed & strThu & strFri &
>> strSat
>> ' Remove any embedded spaces or punctuation.
>> strString = Replace(strString, " ", "")
>> strString = Replace(strString, ".", "")
>> strString = Replace(strString, ",", "")
>> strString = Replace(strString, "-", "")
>>
>> ' Convert to UTC (Coordinated Universal Time).
>> If lngBias > 0 Then
>> strStr1 = Mid(strString, 1, Len(strString) - lngBias)
>> strStr2 = Right(strString, lngBias)
>> strString = strStr2 & strStr1
>> End If
>> If lngBias < 0 Then
>> strStr1 = Mid(strString, 1, -lngBias)
>> strStr2 = Right(strString, Len(strString) + lngBias)
>> strString = strStr2 & strStr1
>> End If
>>
>> ' Convert to a byte array.
>> strByte = ""
>> For k = 0 To 20
>> strHrs = Mid(strString, (k * 8) + 1, 8)
>> strHex = BinaryStrToHexByteStr(strHrs)
>> strByte = strByte & strHex
>> Next
>> SetUserLogonHrs = HexStrToOctet(strByte)
>>
>> End Function
>>
>> Private Function BinaryStrToHexByteStr(ByVal strBinary As String) As
>> String
>> ' Function to convert a binary string of 8 bytes to a hex string of
>> bytes.
>> Dim k As Integer, intValue As Integer
>>
>> intValue = 0
>> For k = 0 To 7
>> intValue = intValue + Val(Mid(strBinary, k + 1, 1)) * (2 ^ k)
>> Next
>> BinaryStrToHexByteStr = Right("0" & CStr(Hex(intValue)), 2)
>>
>> End Function
>>
>> Private Function HexStrToOctet(ByVal strString As String) As Variant
>> ' Function to convert a hex string to an OctetString (byte array).
>> Dim arrbytArray() As Byte, j As Integer
>>
>> ReDim arrbytArray((Len(strString) \ 2) - 1)
>> For j = 1 To Len(strString) \ 2
>> arrbytArray(j - 1) = Val("&H" & Mid(strString, 2 * j - 1, 1)) *
>> 16 _
>> + Val("&H" & Mid(strString, 2 * j, 1))
>> Next
>> HexStrToOctet = arrbytArray
>>
>> End Function
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab -
http://www.rlmueller.net>> --
>>
>>
>>
>
> Just what I looking for. I made the changes to allow the code to run on a
> NT
> domain and it works great.
>
> Thanks very much