尝试保存通讯组时拒绝访问错误

编程入门 行业动态 更新时间:2024-10-20 20:39:09
本文介绍了尝试保存通讯组时拒绝访问错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-27 12:39:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154882.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   通讯

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!