Results 1 to 3 of 3

Thread: Finding network shares

  1. #1
    Join Date
    Jan 2006
    Posts
    74
    Rep Power
    0

    Default Finding network shares

    Dose anyone know the best way to go about detecting each computer on a network and determine if each has a shared resource with a particular name?

    I am seeking a way to give my app the ability to auto detect the server and configure itself. Each client app require a UNC path for the database location and setting it manually is what I currently do.


    This is the Idea

    I would "FindAllComputerNamesOnNetwork" then "FindAllSharesOnEachComputer".

    On Application Startup

    If Datapath := ' ' then
    begin
    Datapath := ' \\' + ComputerNameWithParticularShare + ' \' + ParticularShare
    end;

    Any suggestions appreciated
    Proven Jamaican Point Of Sale Software http://www.lintechsystems.net/

  2. #2
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    Here is a code snippet taken from Google Groups:

    Code:
    function TMainWin.EnumClients(tar:TStrings):DWord;
    var ContinueEnumeration:boolean;
       Function WNetEnumeration(PNetContainer: PNetResource):DWord;
       var BufferSize,NetEntries:DWORD;
           i:Integer;
           NetResources:TNetResources;
           NetHandle:THandle;
           Text:String;
       begin
          Result:=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,
            RESOURCEUSAGE_CONTAINER,PNetContainer,NetHandle);
          if Result<>NO_ERROR then
             exit;
          ContinueEnumeration:=True;
          while ContinueEnumeration do
          begin
             NetEntries:=MaxNetResources;
             BufferSize:=SizeOf(NetResources);
    
    Result:=WNetEnumResource(NetHandle,NetEntries,@NetResources[0],BufferSize);
    
             if Result=NO_ERROR then
             begin
                for i:=0 to Pred(NetEntries)do
                begin
                   if NetResources[i].dwDisplayType=RESOURCEDISPLAYTYPE_SERVER
    then
                   begin
                      text:=NetResources[i].lpRemoteName;
                      while Pos('\',text)=1 do
                         Delete(text,1,1);
                      tar.Add(Text+' '+GetIP(Text));
                   end;
                   if NetResources[i].dwUsage<>RESOURCEUSAGE_CONNECTABLE then
                      WNetEnumeration(@NetResources[i]);
                end;
             end
             else
             begin
                Result:=GetLastError;
                ContinueEnumeration:=Result=ERROR_MORE_DATA;
             end;
          end;
          if NetHandle<>0 then
             WNetCloseEnum(NetHandle);
       end;
    begin
       tar.Clear;
       Result:=WNetEnumeration(nil);
    end;
    This will give you the list of clients.

    You could just set the database path in an ini file once and each client on startup would use those settings. That's more conventional than scanning the whole network for a particular resource.

  3. #3
    Join Date
    Sep 2004
    Posts
    281
    Rep Power
    0

    Default

    What if there appends to be more than one share with the same name on the network......or the server on which the file resides has restrictions preventing you from seeing it........like a fire wall?

    I would think a more robust solution would be needed.
    I would say allow your clients to talk to a configuration server/application that would tell them where the resource is..
    This should eliminate the need for SMB/cifs broadcast which would get killed by some firewalls anyway -> a central/secure setting...etc.

    You could use tcp/ip or some other form of IPC for this kind of thing to work...if you need help ill be willing to try and help..
    Anything or Anyone that fails to grow will eventually die. {AI}
    -------------------------------------------------
    Tomorrow is the future!
    Today Is the Tomorrow you made Yesterday!{AI}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •