Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Sharing files over a network

Posted on 2004-11-10
7
Medium Priority
?
255 Views
Last Modified: 2010-04-05
Can anyone show me how to share a folder (using delphi ... :) )  and how to list the currently shared folders over a network?
0
Comment
Question by:Rayden_The_God
  • 4
  • 3
7 Comments
 

Author Comment

by:Rayden_The_God
ID: 12542156
Ps: if possible using only Delphi 6 or windows api...
0
 
LVL 1

Expert Comment

by:amebikes
ID: 12542799
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 :-)
0
 

Author Comment

by:Rayden_The_God
ID: 12553733
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:amebikes
ID: 12553810
Sorry, LM.PAS is a part of JEDI Code Library.
You can find the library here: http://delphi-jedi.org/CODELIBJCL
0
 

Author Comment

by:Rayden_The_God
ID: 12556241
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....
0
 
LVL 1

Accepted Solution

by:
amebikes earned 1000 total points
ID: 12563526
Hi,
is "lmshare.pas" included?
You can also use this unit.

Here is the link: (just testet :)

http://delphi-jedi.org/APILIBRARY:429110

Download "LanManager.zip"

regards
  amebikes
0
 

Author Comment

by:Rayden_The_God
ID: 12564229
Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

580 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