2013-10-27 54 views
1

设置的密码在服务器中失败。当调用SetPassword时,我收到错误:“异常已被调用的目标抛出。”

Exception.message: Exception has been thrown by the target of an invocation at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)

那么,为什么将这个呼叫工作从本地(开发者)的机器,但是从服务器不 工作?

 `  DirectoryEntry entry = new DirectoryEntry(..); 
      entry.AuthenticationType = AuthenticationTypes.Secure; 
      DirectorySearcher search = new DirectorySearcher(entry); 
      search.Filter = "(&(sAMAccountName=" + userName_ + "))"; 
      DirectoryEntry userEntry = search.FindAll()[0].GetDirectoryEntry(); 
      userEntry.Invoke("SetPassword", new object[] {[email protected]#" 
      userEntry.CommitChanges();` 

编辑:的InnerException是{ “RPC服务器不可用(从HRESULT异常:0x800706BA)。”}

+1

什么是InnerException? – SLaks

+0

如果没有内部异常,TargetInvocationExceptions通常很没用。这可能与您的调用有关,因为它是TargetInvocationException。 –

+0

http://blogs.msdn.com/b/alejacma/archive/2008/04/29/changepassword-method-may-fail-with-targetinvocationexception-net.aspx –

回答

0

是否在同一帐户下的应用运行在两种环境?如果没有,那么根据你的问题,这可能是一个权限问题

+0

什么样的权限问题?如果有权限问题,它是如何在本地机器上工作的? –

+0

@EmreYardımcı只有当程序以管理员身份运行时,它才能调用'SetPassword',如果您执行'以管理员身份运行'以启动程序,那么它会起作用吗?我会把[程序的清单](http://stackoverflow.com/questions/2818179/how-to-force-my-net-app-to-run-as-administrator-on-windows-7)文件' '所以它会为你做这个请求。 –

+0

我真的尝试了,不起作用Scott .. –

相关问题