【问题标题】:Acces denied error when trying to save a distribution group尝试保存通讯组时访问被拒绝错误
【发布时间】:2014-11-19 13:13:51
【问题描述】:

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

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

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

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

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

如果有人能提醒我为什么保存时不使用凭据,将不胜感激。

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);
            } 

【问题讨论】:

    标签: c# visual-studio active-directory


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-07
      • 1970-01-01
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多