Solved

Enumerating shares

Posted on 2002-05-15
4
173 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
  • 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now