W
whosyodaddy1019
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/d...ser_cannot_change_password_winnt_provider.asp
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/d...ser_cannot_change_password_winnt_provider.asp