1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
using System.DirectoryServices; using ActiveDs; try { // ActiveDirectoryのIPアドレス:192.168.1.100 // ドメイン:pr.local string adPath = "LDAP://192.168.1.100/DC=pr,DC=local"; DirectoryEntry de = new DirectoryEntry(adPath); DirectorySearcher schr = new DirectorySearcher(de); schr.SizeLimit = 2147483647; schr.PageSize = 1000; schr.Filter = String.Format("(&(objectClass=user)(samAccountName={0}))", strUserName); SearchResult sr = schr.FindOne(); if (sr == null) { throw new System.ArgumentException("Not found user " + strUserName + " using Active Directory.", "original"); } DirectoryEntry userEntry = sr.GetDirectoryEntry(); string strMail = (string)userEntry.Properties["mail"].Value; if (strMail == "") { throw new ArgumentException("Nothing Mail Address to " + strUserName, "original"); } return strMail; } catch (ArgumentException ex) { throw ex; } |
コメント