类似的,不知道有没有帮助
function GetUsers(GroupName: string; var List: TStringList): Boolean;
type
TNetResourceArray = ^TNetResource; //ÍøÂçÀàÐ͵ÄÊý×é
var
NetResource: TNetResource;
Buf: Pointer;
Count, BufSize, Res: DWord;
Ind: Integer;
lphEnum: THandle;
Temp: TNetResourceArray;
begin
Result := False;
FillChar(NetResource, SizeOf(NetResource), 0); //³õʼ»¯ÍøÂç²ã´ÎÐÅÏ¢
NetResource.lpRemoteName := @GroupName[1]; //Ö¸¶¨¹¤×÷×éÃû³Æ
NetResource.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER; //ÀàÐÍΪ·þÎñÆ÷£¨¹¤×÷×飩
NetResource.dwUsage := RESOURCEUSAGE_CONTAINER;
NetResource.dwScope := RESOURCETYPE_DISK; //ÁоÙÎļþ×ÊÔ´ÐÅÏ¢
//»ñÈ¡Ö¸¶¨¹¤×÷×éµÄÍøÂç×ÊÔ´¾ä±ú
Res := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
RESOURCEUSAGE_CONTAINER, @NetResource, lphEnum);
if Res <> NO_ERROR then Exit; //&Ouml;&acute;&ETH;&ETH;&Ecirc;§°&Uuml;
while True do //&Aacute;&ETH;&frac34;&Ugrave;&Ouml;&cedil;&para;¨&sup1;¤×÷×é&micro;&Auml;&Iacute;&oslash;&Acirc;&ccedil;×&Ecirc;&Ocirc;&acute;
begin
Count := $FFFFFFFF; //&sup2;&raquo;&Iuml;&THORN;×&Ecirc;&Ocirc;&acute;&Ecirc;&yacute;&Auml;&iquest;
BufSize := 8192; //&raquo;&ordm;&sup3;&aring;&Ccedil;&oslash;&acute;ó&ETH;&iexcl;&Eacute;è&Ouml;&Atilde;&Icirc;&ordf;8K
GetMem(Buf, BufSize); //&Eacute;ê&Ccedil;&euml;&Auml;&Uacute;&acute;&aelig;&pound;&not;&Oacute;&Atilde;&Oacute;&Uacute;&raquo;&ntilde;&Egrave;&iexcl;&sup1;¤×÷×é&ETH;&Aring;&Iuml;&cent;
//&raquo;&ntilde;&Egrave;&iexcl;&frac14;&AElig;&Euml;&atilde;&raquo;ú&Atilde;&ucirc;&sup3;&AElig;
Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);
if Res = ERROR_NO_MORE_ITEMS then break; //×&Ecirc;&Ocirc;&acute;&Aacute;&ETH;&frac34;&Ugrave;&Iacute;ê±&Iuml;
if (Res <> NO_ERROR) then Exit; //&Ouml;&acute;&ETH;&ETH;&Ecirc;§°&Uuml;
Temp := TNetResourceArray(Buf);
for Ind := 0 to Count - 1 do //&Aacute;&ETH;&frac34;&Ugrave;&sup1;¤×÷×é&micro;&Auml;&frac14;&AElig;&Euml;&atilde;&raquo;ú&Atilde;&ucirc;&sup3;&AElig;
begin
//&raquo;&ntilde;&Egrave;&iexcl;&sup1;¤×÷×é&micro;&Auml;&frac14;&AElig;&Euml;&atilde;&raquo;ú&Atilde;&ucirc;&sup3;&AElig;&pound;&not;+2±í&Ecirc;&frac34;&Eacute;&frac34;&sup3;&yacute;"//"&pound;&not;&Egrave;&ccedil;//wangfajun=>wangfajun
List.Add(Temp^.lpRemoteName + 2);
Inc(Temp);
end;
end;
Res := WNetCloseEnum(lphEnum); //&sup1;&Oslash;±&Otilde;&Ograve;&raquo;&acute;&Icirc;&Aacute;&ETH;&frac34;&Ugrave;
if Res <> NO_ERROR then exit; //&Ouml;&acute;&ETH;&ETH;&Ecirc;§°&Uuml;
Result := True;
FreeMem(Buf);
end;
function GetServerList(var List: TStringList): Boolean;
type
TNetResourceArray = ^TNetResource; //&Iacute;&oslash;&Acirc;&ccedil;&Agrave;à&ETH;&Iacute;&micro;&Auml;&Ecirc;&yacute;×é
var
NetResource: TNetResource;
Buf: Pointer;
Count, BufSize, Res: DWORD;
lphEnum: THandle;
p: TNetResourceArray;
i, j: SmallInt;
NetworkTypeList: TList;
begin
Result := False;
NetworkTypeList := TList.Create;
List.Clear;
//&raquo;&ntilde;&Egrave;&iexcl;&Otilde;&ucirc;&cedil;&ouml;&Iacute;&oslash;&Acirc;&ccedil;&Ouml;&ETH;&micro;&Auml;&Icirc;&Auml;&frac14;&thorn;×&Ecirc;&Ocirc;&acute;&micro;&Auml;&frac34;&auml;±ú&pound;&not;lphEnum&Icirc;&ordf;·&micro;&raquo;&Oslash;&Atilde;&ucirc;±ú
Res := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
RESOURCEUSAGE_CONTAINER, nil, lphEnum);
if Res <> NO_ERROR then exit; //Raise Exception(Res);//&Ouml;&acute;&ETH;&ETH;&Ecirc;§°&Uuml;
//&raquo;&ntilde;&Egrave;&iexcl;&Otilde;&ucirc;&cedil;&ouml;&Iacute;&oslash;&Acirc;&ccedil;&Ouml;&ETH;&micro;&Auml;&Iacute;&oslash;&Acirc;&ccedil;&Agrave;à&ETH;&Iacute;&ETH;&Aring;&Iuml;&cent;
Count := $FFFFFFFF; //&sup2;&raquo;&Iuml;&THORN;×&Ecirc;&Ocirc;&acute;&Ecirc;&yacute;&Auml;&iquest;
BufSize := 8192; //&raquo;&ordm;&sup3;&aring;&Ccedil;&oslash;&acute;ó&ETH;&iexcl;&Eacute;è&Ouml;&Atilde;&Icirc;&ordf;8K
GetMem(Buf, BufSize); //&Eacute;ê&Ccedil;&euml;&Auml;&Uacute;&acute;&aelig;&pound;&not;&Oacute;&Atilde;&Oacute;&Uacute;&raquo;&ntilde;&Egrave;&iexcl;&sup1;¤×÷×é&ETH;&Aring;&Iuml;&cent;
Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);
if (Res = ERROR_NO_MORE_ITEMS) //×&Ecirc;&Ocirc;&acute;&Aacute;&ETH;&frac34;&Ugrave;&Iacute;ê±&Iuml;
or (Res <> NO_ERROR) //&Ouml;&acute;&ETH;&ETH;&Ecirc;§°&Uuml;
then Exit;
P := TNetResourceArray(Buf);
for I := 0 to Count - 1 do //&frac14;&Ccedil;&Acirc;&frac14;&cedil;÷&cedil;&ouml;&Iacute;&oslash;&Acirc;&ccedil;&Agrave;à&ETH;&Iacute;&micro;&Auml;&ETH;&Aring;&Iuml;&cent;
begin
NetworkTypeList.Add(p);
Inc(P);
end;
//WNetCloseEnum&sup1;&Oslash;±&Otilde;&Ograve;&raquo;&cedil;&ouml;&Aacute;&ETH;&frac34;&Ugrave;&frac34;&auml;±ú
Res := WNetCloseEnum(lphEnum); //&sup1;&Oslash;±&Otilde;&Ograve;&raquo;&acute;&Icirc;&Aacute;&ETH;&frac34;&Ugrave;
if Res <> NO_ERROR then exit;
for J := 0 to NetworkTypeList.Count - 1 do //&Aacute;&ETH;&sup3;&ouml;&cedil;÷&cedil;&ouml;&Iacute;&oslash;&Acirc;&ccedil;&Agrave;à&ETH;&Iacute;&Ouml;&ETH;&micro;&Auml;&Euml;ù&Oacute;&ETH;&sup1;¤×÷×é&Atilde;&ucirc;&sup3;&AElig;
begin //&Aacute;&ETH;&sup3;&ouml;&Ograve;&raquo;&cedil;&ouml;&Iacute;&oslash;&Acirc;&ccedil;&Agrave;à&ETH;&Iacute;&Ouml;&ETH;&micro;&Auml;&Euml;ù&Oacute;&ETH;&sup1;¤×÷×é&Atilde;&ucirc;&sup3;&AElig;
NetResource := TNetResource(NetworkTypeList.Items[J]^); //&Iacute;&oslash;&Acirc;&ccedil;&Agrave;à&ETH;&Iacute;&ETH;&Aring;&Iuml;&cent;
//&raquo;&ntilde;&Egrave;&iexcl;&Auml;&sup3;&cedil;&ouml;&Iacute;&oslash;&Acirc;&ccedil;&Agrave;à&ETH;&Iacute;&micro;&Auml;&Icirc;&Auml;&frac14;&thorn;×&Ecirc;&Ocirc;&acute;&micro;&Auml;&frac34;&auml;±ú&pound;&not;NetResource&Icirc;&ordf;&Iacute;&oslash;&Acirc;&ccedil;&Agrave;à&ETH;&Iacute;&ETH;&Aring;&Iuml;&cent;&pound;&not;lphEnum&Icirc;&ordf;·&micro;&raquo;&Oslash;&Atilde;&ucirc;±ú
Res := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_DISK,
RESOURCEUSAGE_CONTAINER, @NetResource, lphEnum);
if Res <> NO_ERROR then break; //&Ouml;&acute;&ETH;&ETH;&Ecirc;§°&Uuml;
while true do //&Aacute;&ETH;&frac34;&Ugrave;&Ograve;&raquo;&cedil;&ouml;&Iacute;&oslash;&Acirc;&ccedil;&Agrave;à&ETH;&Iacute;&micro;&Auml;&Euml;ù&Oacute;&ETH;&sup1;¤×÷×é&micro;&Auml;&ETH;&Aring;&Iuml;&cent;
begin
Count := $FFFFFFFF; //&sup2;&raquo;&Iuml;&THORN;×&Ecirc;&Ocirc;&acute;&Ecirc;&yacute;&Auml;&iquest;
BufSize := 8192; //&raquo;&ordm;&sup3;&aring;&Ccedil;&oslash;&acute;ó&ETH;&iexcl;&Eacute;è&Ouml;&Atilde;&Icirc;&ordf;8K
GetMem(Buf, BufSize); //&Eacute;ê&Ccedil;&euml;&Auml;&Uacute;&acute;&aelig;&pound;&not;&Oacute;&Atilde;&Oacute;&Uacute;&raquo;&ntilde;&Egrave;&iexcl;&sup1;¤×÷×é&ETH;&Aring;&Iuml;&cent;
//&raquo;&ntilde;&Egrave;&iexcl;&Ograve;&raquo;&cedil;&ouml;&Iacute;&oslash;&Acirc;&ccedil;&Agrave;à&ETH;&Iacute;&micro;&Auml;&Icirc;&Auml;&frac14;&thorn;×&Ecirc;&Ocirc;&acute;&ETH;&Aring;&Iuml;&cent;&pound;&not;
Res := WNetEnumResource(lphEnum, Count, Pointer(Buf), BufSize);
if (Res = ERROR_NO_MORE_ITEMS) //×&Ecirc;&Ocirc;&acute;&Aacute;&ETH;&frac34;&Ugrave;&Iacute;ê±&Iuml;
or (Res <> NO_ERROR) //&Ouml;&acute;&ETH;&ETH;&Ecirc;§°&Uuml;
then break;
P := TNetResourceArray(Buf);
for I := 0 to Count - 1 do //&Aacute;&ETH;&frac34;&Ugrave;&cedil;÷&cedil;&ouml;&sup1;¤×÷×é&micro;&Auml;&ETH;&Aring;&Iuml;&cent;
begin
List.Add(StrPAS(P^.lpRemoteName));
Inc(P);
end;
end;
Res := WNetCloseEnum(lphEnum); //&sup1;&Oslash;±&Otilde;&Ograve;&raquo;&acute;&Icirc;&Aacute;&ETH;&frac34;&Ugrave;
if Res <> NO_ERROR then break; //&Ouml;&acute;&ETH;&ETH;&Ecirc;§°&Uuml;
end;
Result := True;
FreeMem(Buf);
NetworkTypeList.Destroy;
end;