尝试保存通讯组时拒绝访问错误 [英] Acces denied error when trying to save a distribution group

查看:39
本文介绍了尝试保存通讯组时拒绝访问错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行下面显示的代码时,我收到一条错误消息:

When running the code shown below, I am getting an error that states:

发生类型为System.UnauthorizedAccessException"的未处理异常
System.DirectoryServices.dll.附加信息:访问被拒绝.

An unhandled exception of type 'System.UnauthorizedAccessException' occurred in
System.DirectoryServices.dll. Additional information: Access is denied.

它发生在这一行:Group.Save();

我在与 Active Directory 相关的其他脚本中使用了用户名和密码,因此它确实可以访问我需要它做的任何事情.虽然,我之前没有尝试过与 System.DirectoryServices.AccountManagement 库相关的内容.

I have used the username and password in other scripts relating to Active Directory so it does have sufficient access to anything i need it to do. Although, I haven't tried it in relation to the System.DirectoryServices.AccountManagement library before.

我使用的是在管理员模式下运行的 Visual Studio 2013,所以没有在其中运行命令提示符应该没有问题.

I am using Visual Studio 2013 running in admin mode, so there shouldn't be a problem with the command prompt not running in it.

如果有人能告诉我为什么在保存时不使用凭据,我们将不胜感激.

If anyone can give me a heads up as to why it wouldn't be using the credentials when saving, it would be greatly appreciated.

try
            {
                using (PrincipalContext PC = new PrincipalContext(ContextType.Domain, "DOMAIN", "USERNAME", "PASSWORD"))
                {             
                    GroupPrincipal Group = GroupPrincipal.FindByIdentity(PC, "GROUPNAME");
                    DBAccessManager DBAccess = new DBAccessManager();
                    SqlConnection ConnString = new SqlConnection();

                    ConnString.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["SQLCONNECTION"].ToString();
                    List<Employee> SQLEmployees = DBAccess.ReadUserInformation(ConnString.ConnectionString.ToString());

                    foreach (Employee Emp in SQLEmployees)
                    {
                        UserPrincipal PrinicipalUser = UserPrincipal.FindByIdentity(PC, Emp.USERNAME);
                        UserPrincipal ADUser = UserPrincipal.FindByIdentity(PC, Emp.USERNAME);
                        if (PrinicipalUser.IsMemberOf(Group) && String.IsNullOrEmpty(Emp.SAPLOGIN))
                        {
                            Group.Members.Remove(ADUser);
                        }
                        else if (!PrinicipalUser.IsMemberOf(Group) && !String.IsNullOrEmpty(Emp.SAPLOGIN))
                        {
                            Group.Members.Add(ADUser);
                        }
                    }
                    Group.Save();                  
                }
            }
            catch (DirectoryServicesCOMException E)
            {
                Console.WriteLine("Exception: " + E.Message);
            } 

推荐答案

问题原来是分发列表的权限问题

The problem turned out to be a permissions issue on the Distribution List

这篇关于尝试保存通讯组时拒绝访问错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆