help with directoryentry WinNT

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
"InvalidCastException was unhandled: operator 'and' is not defined for
'propertyValueCollection' 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.DirectoryServices


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

Const ADS_UF_PASSWD_CANT_CHANGE = 64

Dim Entry As New
DirectoryEntry("LDAP://infitmn4/dc=fully,dc=qualified,dc=domain";)
Dim DSESearcher As New DirectorySearcher(Entry)
Dim strFilter As String = "(sAMAccountName=" & strUserName
& ")"
Dim objUser As DirectoryEntry

DSESearcher.SearchScope = SearchScope.Subtree
DSESearcher.Filter = strFilter
DSESearcher.PropertiesToLoad.Add("pwdLastSet")
'DSESearcher.PropertiesToLoad.Add("userAccountControl")

Dim objResult As SearchResult = DSESearcher.FindOne

If Not objResult Is Nothing Then
Console.WriteLine("Working account " &
objResult.GetDirectoryEntry.Properties("sAMAccountName").Value.ToString)
objUser = objResult.GetDirectoryEntry
Console.WriteLine("Original value = " &
objUser.Properties("userAccountControl").Value)

Dim objWinNT As New DirectoryEntry("WinNT://Domain/" &
strUserName)
Console.WriteLine(objWinNT.Path)
Dim objProperties = objWinNT.Properties("userFlags")
objProperties = objProperties And Not
ADS_UF_PASSWD_CANT_CHANGE ' this is where i get the error
objWinNT.Properties("userFlags").Value = objProperties
objWinNT.CommitChanges()

'If Not objUser.Properties("userAccountControl").Value
= 544 Then


Else : Console.WriteLine("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/default.asp?url=/library/en-us/adsi/adsi/modifying_user_cannot_change_password_winnt_provider.asp

.



Relevant Pages

  • Active Directory gives up group info for only SOME users
    ... Our ASP.NET app is secured with forms authentication and validates users ... against Active Directory. ... Private _filterAttribute As String ... Dim entry As DirectoryEntry = New DirectoryEntry(_path, domainAndUsername, ...
    (microsoft.public.dotnet.security)
  • AD only gives up group (role) information for SOME users
    ... Our ASP.NET app is secured with forms authentication and validates users ... against Active Directory. ... Private _filterAttribute As String ... Dim entry As DirectoryEntry = New DirectoryEntry(_path, domainAndUsername, ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Need assistance badly!
    ... I have tried cobbling together a script that does this, ... I would use ADO in a VBScript program to retrieve all users with the ... Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName, strCN ... adoConnection.Open "Active Directory Provider" ...
    (microsoft.public.scripting.vbscript)
  • ADSI Authentication Problem in ASP
    ... I've one system in which Active directory is installed. ... That system is the domain controller as well as web ... I need ASP solution. ... Dim oDSObj As IADsOpenDSObject ...
    (microsoft.public.inetserver.misc)
  • ADSI Authentication Problem in ASP
    ... I've one system in which Active directory is installed. ... That system is the domain controller as well as web ... I need ASP solution. ... Dim oDSObj As IADsOpenDSObject ...
    (microsoft.public.inetserver.asp.general)