• 应用动态目录修改域用户


            /// <summary>
            /// 创建用户
            /// </summary>
            /// <param name="Username"></param>
            /// <param name="Userpassword"></param>
            /// <param name="Path"></param>
            /// <returns></returns>
            public bool CreateNTUser(string Username, string Userpassword, string Path)
            {
                DirectoryEntry obDirEntry = null;
                try
                {
                    obDirEntry = new DirectoryEntry("WinNT://WORKGROUP/" + this.txt_ip.Text, this.txt_UserName.Text, this.txt_Password.Text);
                    DirectoryEntry obUser = obDirEntry.Children.Add(Username, "User"); //增加用户名
                    obUser.Properties["FullName"].Add(Username); //用户全称
                    obUser.Invoke("SetPassword", Userpassword); //用户密码
                    obUser.Invoke("Put", "Description", "尹皓测试用");//用户详细描述
                    //obUser.Invoke("Put","PasswordExpired",1); //用户下次登录需更改密码
                    obUser.Invoke("Put", "UserFlags", 66049); //密码永不过期
                    obUser.Invoke("Put", "HomeDirectory", Path); //主文件夹路径
                    obUser.CommitChanges();//保存用户

                    DirectoryEntry dirDomain = new DirectoryEntry("WinNT://" + this.txt_ip.Text, this.txt_UserName.Text, this.txt_Password.Text);
                    DirectoryEntry user = obDirEntry.Children.Find(Username, "User");
                    if (obUser != null)
                    {
                        DirectoryEntry grp = obDirEntry.Children.Find("administrators", "group");
                        if (grp != null)
                        {
                            //grp.Properties["member"].Add(obUser.Properties["distinguishedName"].Value);
                            grp.Properties["member"].Add("yinhao");
                            //grp.Invoke("Add", new object[] { obUser.Path.ToString() });
                            grp.CommitChanges();
                        }
                    }
                    return true;
                }
                catch(Exception ex )
                {
                    MessageBox.Show(ex.Message);
                    return false;
                }
            }
            //删除NT用户
            //传入参数:Username用户名
            public bool DelNTUser(string Username)
            {
                try
                {
                    DirectoryEntry obComputer = new DirectoryEntry("WinNT://WORKGROUP/" + txt_ip.Text, this.txt_UserName.Text, this.txt_Password.Text);//获得计算机实例
                    DirectoryEntry obUser = obComputer.Children.Find(Username, "User");//找得用户
                    obComputer.Children.Remove(obUser);//删除用户
                    return true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return false;
                }
            }
            //修改NT用户密码
            //传入参数:Username用户名,Userpassword用户新密码
            public bool InitNTPwd(string Username, string Userpassword)
            {
                try
                {
                    DirectoryEntry obComputer = new DirectoryEntry("WinNT://WORKGROUP/" + txt_ip.Text, this.txt_UserName.Text, this.txt_Password.Text);
                    DirectoryEntry obUser = obComputer.Children.Find(Username, "User");
                    obUser.Invoke("SetPassword", Userpassword);
                    obUser.CommitChanges();
                    obUser.Close();
                    obComputer.Close();
                    return true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return false;
                }
            }

  • 相关阅读:
    【bzoj2733】[HNOI2012]永无乡 Treap启发式合并
    【bzoj1465/bzoj1045】糖果传递 数论
    【bzoj2768/bzoj1934】[JLOI2010]冠军调查/[Shoi2007]Vote 善意的投票 最小割
    【bzoj4003】[JLOI2015]城池攻占 可并堆
    【bzoj3011】[Usaco2012 Dec]Running Away From the Barn 可并堆
    【bzoj2809】[Apio2012]dispatching 贪心+可并堆
    【bzoj1455】罗马游戏 可并堆+并查集
    DOM的的概述
    wpf多程序集之间共享资源字典--CLR名称空间未定义云云
    WPF的Presenter(ContentPresenter)
  • 原文地址:https://www.cnblogs.com/yinhaosln/p/1105629.html
Copyright © 2020-2023  润新知