// 獲取域信息
procedure TMainFrm
var
Enum: IEnumVariant;
ADsTempObj: OLEVariant;
ADsObj: IADs;
Value: LongWord;
begin
//清空用戶
UserListView
GroupListView
ComputerListView
//獲取枚舉對象
Enum := (Domain
//利用枚舉對象查找
while (Enum
begin
ADsObj := IUnknown(ADsTempObj) as IADs; //獲得臨時對象
if AdsObj
AddUserToList(ADsObj);
if AdsObj
AddGroupToList(ADsObj);
if AdsObj
AddComputerToList(ADsObj);
ADsTempObj:=Null; //釋放OLEVariant
end;
end;
procedure TMainFrm
var aListItem:TListItem;
begin
aListItem:=UserListView
aListItem
aListItem
aListItem
aListItem
// aListItem
end;
procedure TMainFrm
var aListItem:TListItem;
begin
aListItem:=GroupListView
aListItem
aListItem
aListItem
end;
procedure TMainFrm
var aListItem:TListItem;
begin
aListItem:=ComputerListView
aListItem
aListItem
aListItem
end;
procedure TMainFrm
var
UnknownObject: IUnknown;
DomainPath
Domain: IADsContainer;
begin
// 指定域路徑
DomainPath :=
ADUser:= ADSIUsername
ADPass:= ADSIPassword
DomainPath :=
ADUser: ADUser:=
ADUser:=
ADPass:=
// 如果使用用戶登錄了信息
if cbUseLogin
OleCheck(AdsOpenObject(PWideChar(DomainPath)
PWideChar(ADUser)
PWideChar(ADPass)
IID_IADsContainer
UnknownObject))
else
OleCheck(ADsGetObject(PWideChar(DomainPath)
IID_IADsContainer
UnknownObject));
// 設定域對象
Domain := UnknownObject as IADsContainer;
// 從域中獲得信息列表
GetDomainInformation(Domain);
end;
end
備注
*
*
目前該問題還不知如何解決
*
作者
unit Main;
interface
uses
Windows
Dialogs
type
TMainFrm = class(TForm)
Button
ObjMemo: TMemo;
OUMemo: TMemo;
UserMemo: TMemo;
cbUseLogin: TCheckBox;
Obj_Label: TLabel;
OU_Label: TLabel;
Users_Label: TLabel;
procedure Button
private
{ Private declarations }
public
{ Public declarations }
procedure GetADInfo(aUser
end;
//連接 Win NT 目錄服務就是找到域控制器然後綁定到相應的對象上
//綁定可以通過 ADsGetObject 或 ADsOpenObject 函數來實現
//第一個函數使用登錄用戶缺省的信任級別
//第二個函數允許開發者指定特殊的安全信任機制來綁定 ADSI 對象
//缺省條件下
function ADsGetObject(lpszPathName: PWideChar; //第一個參數是對象的路徑名
const riid: TIID; //第二個參數是對象的接口標識符
out obj): HResult; stdcall; external
//ADsOpenObject 函數在不同的安全認證機制下綁定 ADSI 對象
//它主要是通過調用參數返回的用戶名和口令來認證的
function ADsOpenObject(lpszPathName: PWideChar; //第一個參數是對象的路徑名
lpszUserName: PWideChar; //第二個參數是調用者提供的用戶名
lpszPassword: PWideChar; //第三個參數是調用者提供的口令
dwReserved: LongInt; //第四個參數是一個保留的 provider 標識
const riid: TIID; //第五個參數是請求接口的接口標識符
out obj): HResult; stdcall; external
var
MainFrm: TMainFrm;
implementation
{$R *
procedure TMainFrm
var DomainPath
begin
DomainPath :=
ADUser:=
ADUser:=
ADPass:=
GetADInfo(ADUser
end;
procedure TMainFrm
var
UnknownObject: IUnknown;
Enum: IEnumVariant;
ADsTempObj: OLEVariant;
Domain: IADsContainer;
ADsObj: IADs;
Value: LongWord;
begin
// 如果使用AD用戶信息登錄
if cbUseLogin
OleCheck(AdsOpenObject(PWideChar(aDomainPath)
PWideChar(aUser)
PWideChar(aPass)
IID_IADsContainer
UnknownObject))
else
OleCheck(ADsGetObject(PWideChar(aDomainPath)
IID_IADsContainer
UnknownObject));
// 設定域對象
Domain := UnknownObject as IADsContainer;
//獲取枚舉對象
Enum := (Domain
//利用枚舉對象查找
while (Enum
begin
ADsObj := IUnknown(ADsTempObj) as IADs; //獲得臨時對象
ObjMemo
if AdsObj
OUMemo
if AdsObj
UserMemo
//遞歸
GetADInfo(aUser
ADsTempObj:=Null; //釋放OLEVariant
end;
end;
end
備注
*
*
屬性的取值域可以通過JAVA程序得到
From:http://tw.wingwit.com/Article/program/Java/hx/201311/27115.html