0

UserPrincipal を使用して Active Directory のユーザー アカウント プロパティを変更しようとしています。

現在のログオン ユーザーではなく、Active Directory への書き込みアクセス権を持つ特別なアカウントを使用する必要があることを読みました。というわけで、特別アカウントを使ってなりすまし専用クラスを作成しました。しかし、私はまだ持っています

System.UnauthorizedAccessException: General access denied error

user.Save(ctx); で。ライン。

System.Security.Principal.WindowsImpersonationContext newUser = clsImpersonate.ImpersonateUser("ADUser", "ADPassword");

            if (newUser != null)
            {
                PrincipalContext ctx = blAD.GetAdminPrincipalContext();
                UserPrincipal user = blAD.GetUserPrincipal(this.SAMAccount);
                user.Enabled = false;
                user.Save(ctx);
                newUser.Undo();
            }

どうすればこの要件を達成できますか? ありがとう。

4

3 に答える 3

0

別のユーザーとしてプリンシパルにアクセスするには、ユーザーの資格情報を使用して PrincipalContext を定義し、UserPrincipal を取得するときにその PrincipalContext を使用します。

    PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "domain.tld", "ADUser", "ADPassword");
    UserPrincipal user = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, this.SAMAccount);
    if (user != null) 
    {
        user.Enabled = false;
        user.Save();
    }

それでも UnauthorizedAccess Exception が発生する場合は、指定しているアカウントが Active Directory/LDS のユーザー オブジェクトに userAccountControl 属性を書き込むためのアクセス権を持っていない可能性があります。

于 2014-09-26T14:43:45.247 に答える
0

あなたの特別なユーザーにはどのような権限が委任されていますか? userAccountControl問題のユーザーに書き込むことができる必要があります。

于 2012-04-24T15:00:48.267 に答える