private void FillWindowsUserAndGroups(ref DataTable user, ref DataTable group) { #region 获取所有组 //DirectoryEntry m_obDirEntry = new DirectoryEntry("LDAP://" + Environment.MachineName); //DirectorySearcher srch = new DirectorySearcher(m_obDirEntry); ////srch.Filter = "(objectClass=Group)(guests)"; //srch.Filter = "(objectClass=Group)"; //SearchResultCollection results = srch.FindAll(); //foreach (SearchResult src in results) //{ // Response.Write(src.GetDirectoryEntry().Name); //} //oDE.Invoke("accountDisabled", new Object[] { "true" }); //Creating Sites and Virtual Directories Using System.DirectoryServices //(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/creating_a_virtual_directory_using_system_directoryservices.asp) //Using System.DirectoryServices to Configure IIS //http://go.microsoft.com/fwlink/?LinkId=48514 //(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/using_system_directoryservices_to_configure_iis.asp) #endregion DataRow dRow = DataSource.Rows[0]; DirectoryEntry DirEntry = new DirectoryEntry("WinNT://" + Environment.MachineName); try { foreach (DirectoryEntry ChildEntry in DirEntry.Children) { if (DirectoryServicesManager.DirectoryObjectIsOfType(ChildEntry.Path, DirectoryServicesManager.UserSchemaClassName)) { user.Rows.Add(new object[] { user.Rows.Count, ChildEntry.Name, ChildEntry.Properties["FullName"].Value, ChildEntry.Properties["Description"].Value, ChildEntry.Properties["LastLogin"].Value, }); //Response.Write(ChildEntry.SchemaEntry.Path); //Response.Write("<br/>"); } if (DirectoryServicesManager.DirectoryObjectIsOfType(ChildEntry.Path, DirectoryServicesManager.GroupSchemaClassName)) { groupTab.Rows.Add(new object[] { groupTab.Rows.Count, ChildEntry.Name, ChildEntry.Properties["Description"].Value }); } } } catch (Exception) { } finally { DirEntry.Close(); IsFetchedWindows = true; } }
protected void Button1_Click(object sender, EventArgs e) { if (tbxPassword.Text != tbxPwdCfm.Text) { lblMsg.Text = "两次密码确认不一致!"; return; } if (tbxUserAdd.Text.Trim() == string.Empty) { return; } string strGroup = (tbxGroupAdd.Text.Trim() != string.Empty) ? tbxGroupAdd.Text.Trim() : dptGroups.SelectedValue; try { AccountHelper.RunAdminCode(new AccountHelper.ExecuteCode(delegate() { if (tbxGroupAdd.Text.Trim() != string.Empty) { DirectoryServicesManager.AddWindowsGroup("WinNT://" + Environment.MachineName, strGroup, "[SVN-WinAuth]创建的分组", 4); } AccountHelper.CreateUserAccount(tbxUserAdd.Text, tbxPwdCfm.Text, tbxUserAdd.Text, strGroup, "[SVN-WinAuth]创建的用户"); lblMsg.ForeColor = System.Drawing.Color.Green; lblMsg.Text = "创建完成!"; UpdateView(); })); } catch (Exception exp) { lblMsg.Text = "错误:" + exp.Message; } }
protected void gridM_RowDeleting(object sender, GridViewDeleteEventArgs e) { string UserName = gridM.DataKeys[e.RowIndex]["UserName"].ToString(); DataRow dRow = DataSource.Rows[e.RowIndex]; if (dRow["Description"].ToString().IndexOf("SVN-WinAuth") == -1) { lblMsg.Text = "非SVN-WinAuth帐号,请登录控制台修改!"; } else { AccountHelper.RunAdminCode(new AccountHelper.ExecuteCode(delegate() { DirectoryServicesManager.DeleteWindowsUser("WinNT://" + Environment.MachineName, dRow["UserName"].ToString()); lblMsg.Text = "操作成功!"; lblMsg.ForeColor = System.Drawing.Color.Green; UpdateView(); })); } }