Получить список доменов
|
Бог есть. Он просто администрит другой домен...
|
function FillNetLevel(xxx: PNetResource; list: TStrings): Word;
type
PNRArr = ^TNRArr;
TNRArr = array[0..59] of TNetResource;
var
x: PNRArr;
tnr: TNetResource;
I: integer;
EntrReq,
SizeReq,
twx: Integer;
WSName: string;
begin
Result := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY,
RESOURCEUSAGE_CONTAINER, xxx, twx);
if Result = ERROR_NO_NETWORK then
Exit;
if Result = NO_ERROR then
begin
New(x);
EntrReq := 1;
SizeReq := SizeOf(TNetResource) * 59;
while (twx < > 0) and
(WNetEnumResource(twx, EntrReq, x, SizeReq) <> ERROR_NO_MORE_ITEMS) do
begin
for i := 0 to EntrReq - 1 do
begin
Move(x^[i], tnr, SizeOf(tnr));
case tnr.dwDisplayType of
RESOURCEDISPLAYTYPE_DOMAIN:
begin
if tnr.lpRemoteName < > '' then
WSName := tnr.lpRemoteName
else
WSName := tnr.lpComment;
list.Add(WSName);
end;
else
FillNetLevel(@tnr, list);
end;
end;
end;
Dispose(x);
WNetCloseEnum(twx);
end;
end;
|
Итак, слегка подправленный вариант. На форме находится Button и RichEdit
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
RichEdit1: TRichEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Res: TNetResource;
s: TStrings;
implementation
{$R *.dfm}
// Переменная List заполняется списком доменов.
// Функция возвращает код ошибки обращения к сети.
function FillNetLevel(xxx: PNetResource; list: TStrings): Word;
type
PNRArr = ^TNRArr;
TNRArr = array[0..59] of TNetResource;
var
x: PNRArr;
tnr: TNetResource;
I: integer;
EntrReq,
SizeReq,
twx: THandle;
WSName: string;
begin
Result := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY,
RESOURCEUSAGE_CONTAINER, xxx, twx);
if Result = ERROR_NO_NETWORK then
Exit;
if Result = NO_ERROR then
begin
New(x);
EntrReq := 1;
SizeReq := SizeOf(TNetResource) * 59;
while (twx <> 0) and
(WNetEnumResource(twx, EntrReq, x, SizeReq) <>
ERROR_NO_MORE_ITEMS) do
begin
for i := 0 to EntrReq - 1 do
begin
Move(x^[i], tnr, SizeOf(tnr));
case tnr.dwDisplayType of
RESOURCEDISPLAYTYPE_DOMAIN:
begin
if tnr.lpRemoteName <> '' then
WSName := tnr.lpRemoteName
else
WSName := tnr.lpComment;
list.Add(WSName);
end;
else
FillNetLevel(@tnr, list);
end;
end;
end;
Dispose(x);
WNetCloseEnum(twx);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
try
s := TStringList.Create;
FillNetLevel(@Res, S);
RichEdit1.Lines.Assign(s);
S.Free
except
S.Free;
ShowMessage('Не удалось получить список доменов')
end
end;
end.
|