资源简介
C#读取AD域组织架构及用户例子。值得初学者一看。
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;
using System.Collections;
using System.Text.Regularexpressions;
namespace ActiveDirectoryDome
{
class Program
{
static void Main(string[] args)
{
if (TryAuthenticate(“whjh.com“ “lity“ “admins“))
{
Console.WriteLine(“登陆成功!“);
}
else
{
Console.WriteLine(“登陆失败!“);
}
Console.WriteLine(“*******************************************************“);
List group = new List();
group = GetADGroups(“lity“ “whjh.com“ “lity“ “admins“);
foreach (string temp in group)
{
Console.WriteLine(“组名称:“+temp.ToString());
}
Console.ReadLine();
}
///
/// 验证AD用户是否登陆成功
///
/// 域名称
/// 用户名
/// 密码
/// 返回登陆状态
public static bool TryAuthenticate(string domain string username string password)
{
bool isLogin = false;
try
{
DirectoryEntry entry = new DirectoryEntry(string.Format(“LDAP://{0}“ domain) username password);
entry.RefreshCache();
isLogin = true;
}
catch
{
isLogin = false;
}
return isLogin;
}
///
/// 取用户所对应的用户组
///
/// 用户名称
/// 域
/// 登陆用户
/// 登陆密码
///
public static List GetADGroups(string userNamestring domainstring adusernamestring adpassword)
{
List groups = new List();
try
{
var entry = new DirectoryEntry(string.Format(“LDAP://{0}“ domain) adusername adpassword);
entry.RefreshCache();
DirectorySearcher search = new DirectorySearcher(entry);
//search.PropertiesToLoad.Add(“memberof“);
//search.Filter = string.Format(“sAMAccountName={0}“ userName);
//SearchResult result = search.FindOne();
search.Filter = “(&(objectCategory=person)(objectClass=user))“;
search.Sort = new SortOption(“samaccountname“ SortDirection.Ascending);
search.SearchScope = SearchScope.Subtree;
SearchResultCollection resultColl = search.FindAll();
foreach (SearchResult result in resultColl)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2565 2010-08-17 11:06 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome\ActiveDirectoryDome.csproj
文件 7168 2011-11-24 13:45 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome\bin\Debug\ActiveDirectoryDome.exe
文件 15872 2011-11-24 13:45 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome\bin\Debug\ActiveDirectoryDome.pdb
文件 11592 2011-11-24 13:45 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome\bin\Debug\ActiveDirectoryDome.vshost.exe
文件 490 2009-06-11 05:14 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome\bin\Debug\ActiveDirectoryDome.vshost.exe.manifest
文件 1736 2011-11-24 13:45 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome\obj\Debug\ActiveDirectoryDome.csproj.FileListAbsolute.txt
文件 7168 2011-11-24 13:45 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome\obj\Debug\ActiveDirectoryDome.exe
文件 15872 2011-11-24 13:45 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome\obj\Debug\ActiveDirectoryDome.pdb
文件 3818 2011-11-24 13:30 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome\Program.cs
文件 1370 2010-08-17 10:37 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome\Properties\AssemblyInfo.cs
文件 1434 2011-11-24 13:44 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome.sln
..A..H. 29184 2011-11-24 13:48 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome.suo
文件 4269 2011-11-24 13:44 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\ADYUAccount.csproj
文件 1297 2011-11-24 13:44 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\ADYUAccount.csproj.user
文件 389 2011-11-24 14:05 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\ADYUAccount.Publish.xm
文件 8192 2011-11-24 14:14 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\bin\ADYUAccount.dll
文件 17920 2011-11-24 14:14 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\bin\ADYUAccount.pdb
文件 813 2011-11-24 13:54 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\Default.aspx
文件 8720 2011-11-24 14:14 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\Default.aspx.cs
文件 2560 2011-11-24 13:47 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\Default.aspx.designer.cs
文件 498 2011-11-24 13:48 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\obj\Debug\ADYUAccount.csproj.FileListAbsolute.txt
文件 8192 2011-11-24 14:14 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\obj\Debug\ADYUAccount.dll
文件 17920 2011-11-24 14:14 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\obj\Debug\ADYUAccount.pdb
文件 1309 2011-11-24 13:35 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\Properties\AssemblyInfo.cs
文件 7305 2011-11-24 13:45 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\Web.config
目录 0 2010-08-17 11:41 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome\obj\Debug\TempPE
目录 0 2011-11-24 13:35 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\obj\Debug\TempPE
目录 0 2011-11-23 17:57 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome\bin\Debug
目录 0 2011-11-24 13:45 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ActiveDirectoryDome\obj\Debug
目录 0 2011-11-24 14:14 C#读取AD域里用户名或组\dome\ActiveDirectoryDome\ADYUAccount\obj\Debug
............此处省略15个文件信息
相关资源
- cad批量替换文字
- asp.net开发Thread问题集
- LoadingMaskWPF加载数据loading遮罩
- 简易unity屏幕特效代码shader+C#
- winform多线程
- head first c# lab3(入侵者游戏)
- MKAdminlayui+C# 后台管理系统
- AlmProject 自动化生产线的报警监控模块
- InteractiveDataDisplay.WPF
- wpf进度条,wpf等待条,wpf loading
- C#中最最简单浅显易懂的通过最新的
- C#.NET 二次开发 DWG格式的CAD文件
- C#.NET读写DWG格式的CAD文件 DWGdirect_NE
- CAD 基于C#.Net 检查线自相交
- C#执行adb命令操控安卓手机或模拟器
- C# 仿CAD矢量绘图源码
- 难得的C#CAD软件源码,无需编译,VS可
- SimpleCAD(功能全面的cad绘图软件)
- 学生考勤管理系统 C#+ADO.NET+GUI(带数
- 张波老师C#完整视频教程
- ExcelDataReader,可以从excel中读取数据,
- Bunifu Dataviz Advanced 1.0.1
- c# 简单模拟CAD
- Head First_深入浅出C#(中文第2版)_带
- adsl 自动拨号类 源码
- jQuery lazyload-预加载 功能,已经通过运
- wpf实现展开收缩效果(ShrinkSpread)
- C# FileStream寫入檔案、StreamReader讀取、
- AD 操作 Helper类代码
- C# RadioListBox 多选框
评论
共有 条评论