System.DirectoryServices FindOne()调用失败问题?
string DomainName = "LDAP://server/DC=hhsshanghai,DC=com ";
string FilterStr = "(sAMAccountname= " + account + ") ";
System.DirectoryServices.DirectoryEntry entry = new DirectoryEntry(DomainName);
writeLog(2);
System.DirectoryServices.DirectorySearcher FindMe = new System.DirectoryServices.DirectorySearcher(entry);
writeLog(3);
FindMe.Filter = FilterStr;
FindMe.PropertiesToLoad.Add( "cn "); //中文名
FindMe.PropertiesToLoad.Add( "mail "); //mail
writeLog(4);
System.DirectoryServices.SearchResult FindRes = FindMe.FindOne();
writeLog(5);
运行到writeLog(4);都还正确,但FindOne()这一句报错:
事件类型: 错误
事件来源: Service1
事件种类: 无
事件 ID: 0
日期: 2007-2-13
事件: 10:54:26
用户: N/A
计算机: JIAO
描述:
Service cannot be started. System.Runtime.InteropServices.COMException (0x80072020): 出现了一个操作错误。
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at System.DirectoryServices.DirectorySearcher.FindOne()
at MailCheckService.Service_MailCheck.Get_Mail_Address(String account) in F:\project\MailCheckService\MailCheckService\Service_MailCheck.cs:line 229
at MailCheckService.Service_MailCheck.OnStart(String[] args) in F:\project\MailCheckService\MailCheckService\Service_MailCheck.cs:line 52
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
有关更多信息,请参阅在 http://go.microsoft.com/fwlink/events.asp 的帮助和支持中心。
我是在windows服务中写的回报这样的错。
但是如果放在windows form程序中运行就不会报错
------解决方案--------------------你何不用服务调用WINFORM来执行你的操作
------解决方案--------------------