2016-10-05 16 views
0

UserPrincipalを使用してActiveDirectoryにChangePassword機能を実装しようとしています。一個の以上の入力パラメータが無効である - 私はのChangePassword、System.Runtime.InteropServices.COMExceptionの例外を取得し、私のWindows 10マシン上でこれをテストしようとするとSystem.DirectoryServices.AccountManagement.UserPrincipal - ChangePasswordメソッドが例外をスローする

 using System.DirectoryServices.AccountManagement; 

     private PrincipalContext Context { get; set; } 

     ... 
     Context = new PrincipalContext(ContextType.Domain, 
      AdDomain, 
      AdRoot, 
      ContextOptions.SimpleBind, 
      AdUsername, 
      AdPassword) 
     ... 

     public bool ChangePassword(string login, string password, string newPassword, out string message) 
     { 
      using (var foundUser = UserPrincipal.FindByIdentity(Context, IdentityType.SamAccountName, login)) 
      { 
       try 
       { 
        foundUser.ChangePassword(password, newPassword); 
        foundUser.Save(); 
       } 
       catch (Exception e) 
       { 
        message = e.Message; 
        return false; 
       } 

       return true; 
      } 
     } 

:コードは次のようになります。

しかし、同じプロジェクトで同じコードを実行しているときに、Windows 7マシンで同じADドメインに接続すると、エラーなしで実行され、パスワードが変更されます。環境上でこの異なる動作を引き起こす原因は何か、そのエラーはどうして起こるのでしょうか?

+0

http://stackoverflow.com/questions/33717673/system-directoryservices-accountmanagement-principalcontext-broken-after-windows こちらをご覧ください。 –

+0

Windows 10マシンでRegisteredOwnerとRegisteredOrganizationでレジストリを変更しましたが、このエラーは解決しませんでした。 –

答えて

0

コンテキストを作成するときは、ContextOptionsContextOptions.Negotiateに設定してください。 ContextOptions.SimpleBindSetPasswordと記載されている場合は動作しないことがあります。

PrincipalContext oPrincipalContext = new PrincipalContext 
       (ContextType.Domain, "Name", "DefaultOU(if required)", ContextOptions.Negotiate, 
       "Service Account(if required)", "Service password"); 
+0

あなたの答えは整形式である必要があります。 これは私にとってはあまりにも面倒です、私はあなたが中に何を持っているのか分からない、私はあなたのためにそれをフォーマットすることはできません。誰かが助けることができますか? – pix

+0

達成する必要があるのは何ですか? –

関連する問題