Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: Logon Hours

HTVi
TV Discussion Newsgroups

Logon Hours
M[ at ]rk 6/15/2007 12:21:00 PM
I manage a Windows NT network and use User Manager or a Net User command to
change a users logon hours, however I'm looking to see if it possible to do
this via vbscript.

I've done various searches on the internet and found scripts to do different
things to a user account except change their logon hours. The nearest I've
got is to either copy another users hours or read and display the users login
hours.

Various sites mention the loginhours property, but not how to update it
Re: Logon Hours
"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> 6/15/2007 3:46:19 PM

"M[ at ]rk" <Mrk[ at ]discussions.microsoft.com> wrote in message
news:8BE255FC-1EC9-4AFA-8C87-3615E5B19149[ at ]microsoft.com...
[Quoted Text]
>I manage a Windows NT network and use User Manager or a Net User command to
> change a users logon hours, however I'm looking to see if it possible to
> do
> this via vbscript.
>
> I've done various searches on the internet and found scripts to do
> different
> things to a user account except change their logon hours. The nearest I've
> got is to either copy another users hours or read and display the users
> login
> hours.
>
> Various sites mention the loginhours property, but not how to update it

The logonHours attribute is OctetString, which is a Byte Array. There are
ways to read a byte array in VBScript. For example, this program displays
the logonHours settings for a user:

http://www.rlmueller.net/Document%20LogonHours.htm

However, VBScript cannot create or modify byte arrays. I have seen various
attempts to write byte values to an external file and read the contents back
as a byte array, but they have not worked for me. I have never found any
VBScript code that can assign values to logonHours (other than to copy the
attribute from one user to another).

I have written Visual Basic code to assign logonHours, but VB can declare a
variable as a byte array.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


Re: Logon Hours
"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> 6/15/2007 4:06:00 PM

"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> wrote in
message news:eVInWR2rHHA.4860[ at ]TK2MSFTNGP02.phx.gbl...
[Quoted Text]
>
> "M[ at ]rk" <Mrk[ at ]discussions.microsoft.com> wrote in message
> news:8BE255FC-1EC9-4AFA-8C87-3615E5B19149[ at ]microsoft.com...
>>I manage a Windows NT network and use User Manager or a Net User command
>>to
>> change a users logon hours, however I'm looking to see if it possible to
>> do
>> this via vbscript.
>>
>> I've done various searches on the internet and found scripts to do
>> different
>> things to a user account except change their logon hours. The nearest
>> I've
>> got is to either copy another users hours or read and display the users
>> login
>> hours.
>>
>> Various sites mention the loginhours property, but not how to update it

I just realized you have an NT domain. The WinNT provider exposes the Active
Directory attribute as loginHours. If the NT attribute is a byte array, my
previous reply is valid for loginHours as well.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


Re: Logon Hours
M[ at ]rk 6/15/2007 8:27:06 PM


"Richard Mueller [MVP]" wrote:

[Quoted Text]
>
> "Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> wrote in
> message news:eVInWR2rHHA.4860[ at ]TK2MSFTNGP02.phx.gbl...
> >
> > "M[ at ]rk" <Mrk[ at ]discussions.microsoft.com> wrote in message
> > news:8BE255FC-1EC9-4AFA-8C87-3615E5B19149[ at ]microsoft.com...
> >>I manage a Windows NT network and use User Manager or a Net User command
> >>to
> >> change a users logon hours, however I'm looking to see if it possible to
> >> do
> >> this via vbscript.
> >>
> >> I've done various searches on the internet and found scripts to do
> >> different
> >> things to a user account except change their logon hours. The nearest
> >> I've
> >> got is to either copy another users hours or read and display the users
> >> login
> >> hours.
> >>
> >> Various sites mention the loginhours property, but not how to update it
>
> I just realized you have an NT domain. The WinNT provider exposes the Active
> Directory attribute as loginHours. If the NT attribute is a byte array, my
> previous reply is valid for loginHours as well.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>

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


Re: Logon Hours
"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> 6/16/2007 7:50:02 PM

[Quoted Text]
> 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
--


Re: Logon Hours
M[ at ]rk 6/18/2007 10:45:00 AM


"Richard Mueller [MVP]" wrote:

[Quoted Text]
>
> > 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
Re: Logon Hours
"Richard Mueller [MVP]" <rlmueller-nospam[ at ]ameritech.nospam.net> 6/18/2007 12:27:32 PM

"M[ at ]rk" <Mrk[ at ]discussions.microsoft.com> wrote in message
news:22FD0915-A80A-49E2-813F-363C95A9C296[ at ]microsoft.com...
[Quoted Text]
>
>
> "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

Glad to here it worked.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen