Link to home
Start Free TrialLog in
Avatar of Rayden_The_God
Rayden_The_God

asked on

Sharing files over a network

Can anyone show me how to share a folder (using delphi ... :) )  and how to list the currently shared folders over a network?
Avatar of Rayden_The_God
Rayden_The_God

ASKER

Ps: if possible using only Delphi 6 or windows api...
Hello,
to enumerate all shares you have to include the unit LM.PAS in your uses clause.
Noe you can try this example code:

<pre>
procedure TForm1.btnEnumClick(Sender: TObject);
type
  PShareInfo2 = ^TShareInfo2;
  _SHARE_INFO_2 = record
    shi2_netname: LPWSTR;
    shi2_type: DWORD;
    shi2_remark: LPWSTR;
    shi2_permissions: DWORD;
    shi2_max_uses: DWORD;
    shi2_current_uses: DWORD;
    shi2_path: LPWSTR;
    shi2_passwd: LPWSTR;
  end;
  TShareInfo2 = _SHARE_INFO_2;
  SHARE_INFO_2 = _SHARE_INFO_2;
var
  Buffer     : Pointer;
  dwEntries  : DWORD;
  dwTotal    : DWORD;
  lIndex     : DWORD;
  dwResult   : DWORD;
  p          : PSHAREINFO2;
  servername  : String;
  sShareType : String;
begin
  lIndex := 0;
  servername := '';
  dwResult := NetShareEnum(
       nil, // or PAnsiChar(\\servername)
       2,
       Buffer,
       MAX_PREFERRED_LENGTH,
       dwEntries,
       dwTotal,
       @lIndex
       );
  if (dwResult = ERROR_SUCCESS)
     or
     (dwResult = ERROR_MORE_DATA) then
  begin
    p := PSHAREINFO2 (Buffer);
    for lIndex := 0 to dwEntries -1 do
    begin
      Case p.shi2_type of
        STYPE_DISKTREE :
          sShareType := 'Disk Drive';
        STYPE_PRINTQ   :
          sShareType := 'Print Queue';
        STYPE_DEVICE   :
          sShareType := 'Communication device';
        STYPE_IPC      :
          sShareType := 'Interprocess communication (IPC)';
        STYPE_SPECIAL  :
          sShareType := 'Administrative Share / IPC';
        else
          begin
            sShareType := 'Unknown';
          end;
      end;
      // Test output in Memo
      M.Lines.Add(Format('netname:%s, path:%s, type:%s, remark:%s',
                  [p.shi2_netname, p.shi2_path, sShareType, p.shi2_remark]));
      inc(p);
    end;
  end;
  NetAPIBufferFree(Buffer);
end;
</pre>

To add a new share you can use the function "NetShareAdd".

Hope it helps :-)
Ok but I can't find LM.PAS in delphi 6 where can I get it ?
Or what are the values of the constants:STYPE_DISKTREE  STYPE_PRINTQ  etc
Sorry, LM.PAS is a part of JEDI Code Library.
You can find the library here: http://delphi-jedi.org/CODELIBJCL
Ok I downloaded jedi but still I can't find Lm.pas ...
Please could you check if the link is the good one?
maybe it's not in jedi....
ASKER CERTIFIED SOLUTION
Avatar of amebikes
amebikes

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!