Resolved my issue by using "Imports System.DirectoryServices.AccountManagement"
Project was working well in XP but not in Windows 7
Replaced:
Dim domainEntry As DirectoryServices.DirectoryEntry
Dim searcher As DirectoryServices.DirectorySearcher
Dim results As DirectoryServices.SearchResultCollection
Dim domainLogin As String
Dim fullName As String
domainLogin = User.Identity.Name
'Strip off domain prefix
domainLogin = domainLogin.Substring(domainLogin.IndexOf("\") + 1, domainLogin.Length - domainLogin.IndexOf("\") - 1)
domainEntry = New DirectoryServices.DirectoryEntry("LDAP://domainname.com", "domainname\username", "Password")
searcher = New DirectoryServices.DirectorySearcher(domainEntry, "(SAMAccountname=" + domainLogin + ")")
results = searcher.FindAll()
with:
Dim domainEntry As DirectoryServices.DirectoryEntry
Dim searcher As DirectoryServices.DirectorySearcher
Dim results As DirectoryServices.SearchResultCollection
Dim domainLogin As String
Dim fullName As String
domainLogin = User.Identity.Name
'Strip off domain prefix
domainLogin = domainLogin.Substring(domainLogin.IndexOf("\") + 1, domainLogin.Length - domainLogin.IndexOf("\") - 1)
Dim context As PrincipalContext = New PrincipalContext(ContextType.Domain)
Dim foundUser As UserPrincipal = UserPrincipal.FindByIdentity(context, "username")
domainEntry = CType(foundUser.GetUnderlyingObject(), DirectoryEntry)
searcher = New DirectoryServices.DirectorySearcher(domainEntry, "(SAMAccountname=" + domainLogin + ")")
results = searcher.FindAll()
No comments:
Post a Comment