Solved

Enumerating shares

Posted on 2002-05-15
4
178 Views
Last Modified: 2011-10-03
Hi, I've looked around a bit for an API call to enumerate shares when given a machine name, but I couldnt find one.

Like - GetShares('\\SomePC')

I only need directories, btw, not printers and such.

Thank you,
Pede
0
Comment
Question by:pede
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
edey earned 50 total points
ID: 7011422
there, actually, some functions to help you - WNetOpenEnum & WNetEnumResource. Knowing that I was able to find this example : http://groups.google.com/groups?hl=en&lr=lang_en&frame=right&th=1b65acc734f96857&seekm=3ba88bd6%241_1%40dnews#link14

The following example will return a list of all known computer names on the
LAN.

procedure EnumNetResources(List: TStrings);

  procedure EnumFunc(NetResource: PNetResource);
  var
    Enum: THandle;
    Count, BufferSize: DWORD;
    Buffer: array[0..16384 div SizeOf(TNetResource)] of TNetResource;
    i: Integer;
  begin
    if WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, NetResource,
Enum) = NO_ERROR then
    try
      Count := $FFFFFFFF;
      BufferSize := SizeOf(Buffer);
      while WNetEnumResource(Enum, Count, @Buffer, BufferSize) = NO_ERROR do
        for i := 0 to Count - 1 do
        begin
          if Buffer[i].dwDisplayType = RESOURCEDISPLAYTYPE_SERVER then
            List.Add(Buffer[i].lpRemoteName);
          if (Buffer[i].dwUsage and RESOURCEUSAGE_CONTAINER) > 0 then
            EnumFunc(@Buffer[i])
        end;
    finally
      WNetCloseEnum(Enum);
    end;
  end;

begin
  List.Clear;
  EnumFunc(nil);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  EnumNetResources(ListBox1.Items);
end;


GL
Mike
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7012900
listening
0
 
LVL 1

Author Comment

by:pede
ID: 7013103
Hi, Im not at work now, but I will have a closer look when I get there. I did find those two functions though, and I dont need to find computers on the network. I already got the computername, I need the shared directories on the computer. Maybe that is possible with those functions too, but Im not sure how.
0
 
LVL 1

Author Comment

by:pede
ID: 7287908
Hi, I had forgot all about this question.

A few hours ago I searched Google for 'enumerating shares' because the above question was starting to get urgent. And as the very first result I get my own question on EE :-) After fiddling around for a while I solved it with the enum functions, thanks for the suggestions.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question