zoukankan      html  css  js  c++  java
  • 应用动态目录修改域用户

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

  • 相关阅读:
    jquery ajax下拉框省市联动效果实现代码
    冒泡排序算法
    Ext.form.ComboBox调用store.filterBy失效问题
    高性能建站之前端优化篇
    不用任何插件实现 WordPress 的彩色标签云
    Javascript 实现select的美化
    RabbitMQ安装与测试
    Select 下拉列表选择插件 (包含下拉选择图片,下拉grid等)
    Javascript 通过cookie记录浏览记录
    ActiveMQ安装与测试
  • 原文地址:https://www.cnblogs.com/yinhaosln/p/1105629.html
Copyright © 2011-2022 走看看