惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - ZH.net

在vb.net中通过ODBC从Oracle 9i向Access倒数据 从SQLSERVER向ORACLE8迁移的技术实现方案 Part V [转] 从SQLSERVER向ORACLE8迁移的技术实现方案 PartIV [转] 从SQLSERVER向ORACLE8迁移的技术实现方案 PartIII [转] 从SQL SERVER向ORACLE的迁移方案[转] PartII Sql Server 转入 Oracle part I (转自网络) 在 .NET 中使用 Oracle 数据库事务 作者:Jason Price 转自oracle.com Oracle Trigger(转自网络) Oracle的分页以及sequence 一些正则表达式 - ZH.net - 博客园 接昨日,将上传至oracle的excel文件下载下来 将文件(word,excel等)存入oracle的一个字段 .net studio 2005操作dbf文件 Web利用Gloabl.asax实现多线程任务 一個Check AD的类。from MSDN 一些JS ViewState的一些学习笔记 发mail时smtp服务器设置的一个问题 datagrid前加checkbox
maintain AD(将一个账号移动到另一个群组)
ZH.net · 2005-09-16 · via 博客园 - ZH.net

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.DirectoryServices;
using ActiveDs;
using System.Text;
using System.Data.SqlClient;
using System.Security.Principal;
namespace ACDR
{

 public class domain : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.Button btnadd;
  protected System.Web.UI.WebControls.Button btnremove;
  protected System.Web.UI.WebControls.Button btnsave;
  protected System.Web.UI.WebControls.ListBox lstall;
  protected System.Web.UI.WebControls.ListBox lstgroup;
  protected System.Web.UI.WebControls.DropDownList DrpGroup;
  private void Page_Load(object sender, System.EventArgs e)
  {
   //DirectoryEntry de=new DirectoryEntry("LDAP://DC=aopen,DC=com");
  
   
   if (Session["Uid"]==null)
   {
    //Response.Write(Session["Uid"]);
     Response.Redirect("logon.aspx");
   }
   DirectoryEntry domain = new DirectoryEntry("LDAP://DC=Hipro,DC=com");
             
   //int usr=(int) domain.Properties[""]
   
   if(!Page.IsPostBack)
   {

//    string tab = "    ";
//    foreach(string key in domain.Properties.PropertyNames)
//    {
//     Response.Write(tab + key + " = ");
//    }
                //groups
//    
    btnadd.Enabled=false;
    btnremove.Enabled=false;
    btnsave.Enabled=false;
    DirectorySearcher src = new DirectorySearcher(domain,"(objectCategory=group)");
    //int val = (int) (ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_GLOBAL_GROUP);    
    //string query = "(&(objectCategory=group)(groupType:1.2.840.113556.1.4.804:=" + val.ToString() + "))";
    int val = (int) (ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_GLOBAL_GROUP| ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_SECURITY_ENABLED);
    string query = "(&(objectCategory=group)(groupType=" + val.ToString() + "))";

    src.Filter = query;
    
    ListItem item=new ListItem("","");
    DrpGroup.Items.Add(item);
    foreach(SearchResult res in src.FindAll())
    {
     //Response.Write(res.Path);
     string strFilter="I";
     DirectoryEntry group = new DirectoryEntry(res.Path);
     if(group.Properties["sAMAccountName"].Value.ToString().ToUpper().IndexOf(strFilter)>=0)
     {
      item=new ListItem(group.Properties["sAMAccountName"].Value.ToString(),res.Path);
      DrpGroup.Items.Add(item);
     }
    }
      //users
    DirectorySearcher dirsearcher = new DirectorySearcher(domain);
    //dirsearcher.Filter = ("(objectclass = user)");
    dirsearcher.Filter ="(&(objectclass=user)(objectcategory=person))";
    dirsearcher.SearchScope = SearchScope.Subtree;
    dirsearcher.Sort =new SortOption("sAMAccountName", SortDirection.Ascending ); //Sort by Name
    foreach (SearchResult result in dirsearcher.FindAll())
    {
     DirectoryEntry de = result.GetDirectoryEntry();
                  
     //sb.Append("UserName: ");
     item=new ListItem(de.Properties["sAMAccountName"].Value.ToString(),de.Path);
    
     lstall.Items.Add(item);
     //sb.Append("<br />");
    }
     
   }

  }
   
 
  #region Web Form 設計工具產生的程式碼
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 此為 ASP.NET Web Form 設計工具所需的呼叫。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
  /// 這個方法的內容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.DrpGroup.SelectedIndexChanged += new System.EventHandler(this.DrpGroup_SelectedIndexChanged);
   this.btnsave.Click += new System.EventHandler(this.btnsave_Click);
   this.btnadd.Click += new System.EventHandler(this.btnadd_Click);
   this.btnremove.Click += new System.EventHandler(this.btnremove_Click);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion


  private void DrpGroup_SelectedIndexChanged(object sender, System.EventArgs e)
  {
   lstgroup.Items.Clear();
   if(DrpGroup.SelectedIndex!=0)
   {
    btnadd.Enabled=true;
    btnremove.Enabled=true;
    btnsave.Enabled=true;
    DirectoryEntry group = new DirectoryEntry(DrpGroup.SelectedValue);
    object members = group.Invoke("members",null);
    ListItem item;    
    foreach( object member in (IEnumerable) members)
    {
     DirectoryEntry x = new DirectoryEntry(member);     
     item=new ListItem(x.Properties["sAMAccountName"].Value.ToString(),x.Path);
     lstgroup.Items.Add(item);
    }

   }
   else
   {
    btnadd.Enabled=false;
    btnremove.Enabled=false;
    btnsave.Enabled=false;
   }
   
  }

  private void btnadd_Click(object sender, System.EventArgs e)
  {
      bool Flg=true;
   int j;
   foreach(ListItem item in lstall.Items)
   {
    if(item.Selected)
    {
     Flg=true;
     for (j=0;j<= lstgroup.Items.Count-1;j++)
     {
      if (lstgroup.Items[j].Value==item.Value)//如果右邊框已經有選中的item則不添加過去,沒有則添加過去
      {
       Flg=false;
       break;
      }
     }
     if(Flg==true){
      lstgroup.Items.Add(new ListItem (item.Text,item.Value));}
    }
   }
  }

  private void btnremove_Click(object sender, System.EventArgs e)
  {
      int count=lstgroup.Items.Count;
   int i=count-1;
   while(i>-1)
   {
             ListItem item=lstgroup.Items[i];
    if(item.Selected)
    {
           lstgroup.Items.RemoveAt(i);
    }
     i=i-1;
   }
  }

  //保存users到group
  private void btnsave_Click(object sender, System.EventArgs e)
  {
   //remove users from group
   if(DrpGroup.SelectedIndex!=0)
   {
    try
    {
     DirectoryEntry group= new DirectoryEntry(DrpGroup.SelectedValue,"Administrator","");

     object members = group.Invoke("members",null);
     foreach( object member in (IEnumerable) members)
     {
      DirectoryEntry x = new DirectoryEntry(member);
      String userDN = x.Properties["distinguishedName"].Value.ToString();
      group.Properties["member"].Remove(userDN);
      group.CommitChanges();
     }
     //add users
     foreach(ListItem item in lstgroup.Items)
     {
      DirectoryEntry x = new DirectoryEntry(item.Value);
      group.Properties["member"].Add(x.Properties["distinguishedName"].Value);
      //Commit the changes to the directory.     
      group.CommitChanges();
     }
     Response.Write("<script>alert('AD Account Modify Success!');</script>");
    }
    catch(Exception ex)        
     {
     //Response.Write(ex.ToString() );
     Response.Write("<script>alert('AD Account Modify Fail,Pls Contact Your Administrator Error:'+ '" + ex.Message+"');</script>");
     
     //throw new Exception( ex.Message);
     }
     
    }
  }


 }

}