S
sunyb
Unregistered / Unconfirmed
GUEST, unregistred user!
因为不懂WNetOpenEnum的用法,哪里有关于它的说明?
以下是我用listview来显示有关信息,但无法获得工作组:
procedure TForm1.Button1Click(Sender: TObject);
begin
listview1.Items.Clear;
GetDomainList(Listview1);
end;
////////////////////////////////////////
function TForm1.GetIP(Name:String):String;
var
WSAData: TWSAData;
HostEnt: PHostEnt;
sIP: string;
begin
WSAStartup(2, WSAData);
HostEnt := gethostbyname(PChar(Name));
if HostEnt <> nil then
begin
with HostEnt^ do
sIP := Format('%d.%d.%d.%d', [Byte(h_addr^[0]), Byte(h_addr^[1]), Byte(h_addr^[2]), Byte(h_addr^[3])]);
end;
WSACleanup;
result:= sIP;
end;
///////////////////////////////////////
procedure TForm1.GetDomainList(Myview:TLISTView);
var itm: TListItem;
i : Integer;
ErrCode : Integer;
NetRes : Array[0..1023] of TNetResource;
EnumHandle : Thandle;
EnumEntries : Dword;
BufferSize : Dword;
ComputerIP,ComputerName:String;
begin
//try
With NetRes[0] do begin
dwScope :=RESOURCE_GLOBALNET;
dwType :=RESOURCETYPE_ANY;
dwDisplayType :=RESOURCEDISPLAYTYPE_DOMAIN;
dwUsage :=RESOURCEUSAGE_CONNECTABLE;
lpLocalName :=NIL;
lpRemoteName :=NIL;
lpComment :=NIL;
lpProvider :=NIL;
end;
{ get net root }
ErrCode:=WNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
RESOURCEUSAGE_CONTAINER,
@NetRes[0],
EnumHandle
);
If ErrCode=NO_ERROR then begin
EnumEntries:=1;
BufferSize:=SizeOf(NetRes);
ErrCode:=WNetEnumResource(EnumHandle,EnumEntries,@NetRes[0],BufferSize);
WNetCloseEnum(EnumHandle);
ErrCode:=WNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
RESOURCEUSAGE_CONNECTABLE,
@NetRes[0],
EnumHandle
);
EnumEntries:=1024;
BufferSize:=SizeOf(NetRes);
ErrCode:=WNetEnumResource(
EnumHandle,
EnumEntries,
@NetRes[0],
BufferSize
);
for i:=0 to 1023 do
if NetRes.lpRemoteName='' then Exit
else begin
ComputerName:=Copy(NetRes.lpRemoteName,3,Length(NetRes.lpRemoteName)-2);
ComputerIP:=GetIP(ComputerName);
itm := Myview.Items.Add;
itm.Caption := inttostr(i+1); //序号
itm.SubItems.Add(ComputerName); //计算机名称
itm.SubItems.Add(NetRes.********); //<==============取得工作组用什么变量
itm.SubItems.Add(NetRes.lpComment); //计算机说明
itm.SubItems.Add(ComputerIP); //IP地址
end;
end;
end;
以下是我用listview来显示有关信息,但无法获得工作组:
procedure TForm1.Button1Click(Sender: TObject);
begin
listview1.Items.Clear;
GetDomainList(Listview1);
end;
////////////////////////////////////////
function TForm1.GetIP(Name:String):String;
var
WSAData: TWSAData;
HostEnt: PHostEnt;
sIP: string;
begin
WSAStartup(2, WSAData);
HostEnt := gethostbyname(PChar(Name));
if HostEnt <> nil then
begin
with HostEnt^ do
sIP := Format('%d.%d.%d.%d', [Byte(h_addr^[0]), Byte(h_addr^[1]), Byte(h_addr^[2]), Byte(h_addr^[3])]);
end;
WSACleanup;
result:= sIP;
end;
///////////////////////////////////////
procedure TForm1.GetDomainList(Myview:TLISTView);
var itm: TListItem;
i : Integer;
ErrCode : Integer;
NetRes : Array[0..1023] of TNetResource;
EnumHandle : Thandle;
EnumEntries : Dword;
BufferSize : Dword;
ComputerIP,ComputerName:String;
begin
//try
With NetRes[0] do begin
dwScope :=RESOURCE_GLOBALNET;
dwType :=RESOURCETYPE_ANY;
dwDisplayType :=RESOURCEDISPLAYTYPE_DOMAIN;
dwUsage :=RESOURCEUSAGE_CONNECTABLE;
lpLocalName :=NIL;
lpRemoteName :=NIL;
lpComment :=NIL;
lpProvider :=NIL;
end;
{ get net root }
ErrCode:=WNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
RESOURCEUSAGE_CONTAINER,
@NetRes[0],
EnumHandle
);
If ErrCode=NO_ERROR then begin
EnumEntries:=1;
BufferSize:=SizeOf(NetRes);
ErrCode:=WNetEnumResource(EnumHandle,EnumEntries,@NetRes[0],BufferSize);
WNetCloseEnum(EnumHandle);
ErrCode:=WNetOpenEnum(
RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
RESOURCEUSAGE_CONNECTABLE,
@NetRes[0],
EnumHandle
);
EnumEntries:=1024;
BufferSize:=SizeOf(NetRes);
ErrCode:=WNetEnumResource(
EnumHandle,
EnumEntries,
@NetRes[0],
BufferSize
);
for i:=0 to 1023 do
if NetRes.lpRemoteName='' then Exit
else begin
ComputerName:=Copy(NetRes.lpRemoteName,3,Length(NetRes.lpRemoteName)-2);
ComputerIP:=GetIP(ComputerName);
itm := Myview.Items.Add;
itm.Caption := inttostr(i+1); //序号
itm.SubItems.Add(ComputerName); //计算机名称
itm.SubItems.Add(NetRes.********); //<==============取得工作组用什么变量
itm.SubItems.Add(NetRes.lpComment); //计算机说明
itm.SubItems.Add(ComputerIP); //IP地址
end;
end;
end;