Solved

Enumerating shares

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 166
QRReport  TQrmemo vertical stretching 1 53
When i run adoquery my application freezes 26 179
MS Access from Delphi 31 60
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

829 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