Solved

Enumerating shares

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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