help with directoryentry WinNT

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • whosyodaddy1019@hotmail.com

    #1

    help with directoryentry WinNT

    In my hunt to change the "User Cannot Change password" attribute in
    active directory so that its unchecked, I read that it is easier to use
    WinNT instead of LDAP. But im having issues getting it to work. When it
    gets to the part where it sets the desired attribute, i get a error
    "InvalidCastExc eption was unhandled: operator 'and' is not defined for
    'propertyValueC ollection' and type 'integer'" Im new to the vb.net work
    and not exacly sure what this means. I found the code for vbs and i
    think i translated it correctly but oviously not. Can anyone help me
    out, thanks in advance

    Imports System
    Imports System.Director yServices


    Namespace ActiveDirectory Search
    Public Class ADSearch
    Shared Sub main(ByVal strUserName As String)

    Const ADS_UF_PASSWD_C ANT_CHANGE = 64

    Dim Entry As New
    DirectoryEntry( "LDAP://infitmn4/dc=fully,dc=qua lified,dc=domai n")
    Dim DSESearcher As New DirectorySearch er(Entry)
    Dim strFilter As String = "(sAMAccountNam e=" & strUserName
    & ")"
    Dim objUser As DirectoryEntry

    DSESearcher.Sea rchScope = SearchScope.Sub tree
    DSESearcher.Fil ter = strFilter
    DSESearcher.Pro pertiesToLoad.A dd("pwdLastSet" )
    'DSESearcher.Pr opertiesToLoad. Add("userAccoun tControl")

    Dim objResult As SearchResult = DSESearcher.Fin dOne

    If Not objResult Is Nothing Then
    Console.WriteLi ne("Working account " &
    objResult.GetDi rectoryEntry.Pr operties("sAMAc countName").Val ue.ToString)
    objUser = objResult.GetDi rectoryEntry
    Console.WriteLi ne("Original value = " &
    objUser.Propert ies("userAccoun tControl").Valu e)

    Dim objWinNT As New DirectoryEntry( "WinNT://Domain/" &
    strUserName)
    Console.WriteLi ne(objWinNT.Pat h)
    Dim objProperties = objWinNT.Proper ties("userFlags ")
    objProperties = objProperties And Not
    ADS_UF_PASSWD_C ANT_CHANGE ' this is where i get the error
    objWinNT.Proper ties("userFlags ").Value = objProperties
    objWinNT.Commit Changes()

    'If Not objUser.Propert ies("userAccoun tControl").Valu e
    = 544 Then


    Else : Console.WriteLi ne("No Object found")
    End If


    End Sub
    End Class
    End Namespace

    PS here is the link to the VBS code i used
    http://msdn.microsoft.com/library/de...t_provider.asp

Working...