Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Share a folder\ directory 1

Status
Not open for further replies.

earlrainer

Programmer
Mar 1, 2002
170
IN
Hi guys,

is it possible through delphi to create a directory\folder and share it (i.e save my lazy self from picking each folder, right clicking and going to share option)

Thanks
keep :)
 
As far as I can see - it's not possible with any Delphi methods/properties. The only object that offers a glimpse of sharing is TFileStream. I tried creating a directory with CreateDir, then tried to access it using the filestream in the hope that it would see the directory as a "directory file" but I couldn't get this to work. Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Search on Torry for the word 'sharing' (without the quotes) s-)

HTH
TonHu
 
Here's an example:
Code:
  type
    SHARE_INFO_2 = record
      shi2_netname : pWideChar;
      shi2_type    : DWORD;
      shi2_remark  : pWideChar;
      shi2_permissions : DWORD;
      shi2_max_uses    : DWORD;
      shi2_current_uses: DWORD;
      shi2_path        : pWideChar;
      shi2_passwd      : pWideChar;
    end;

    PSHARE_INFO_2 = ^SHARE_INFO_2;

    const
      NERR_SUCCESS   = 0;
      STYPE_DISKTREE = 0;
      STYPE_PRINTQ   = 1;
      STYPE_DEVICE   = 2;
      STYPE_IPC      = 3;
      ACCESS_READ    = $01;
      ACCESS_WRITE   = $02;
      ACCESS_CREATE  = $04;
      ACCESS_EXEC    = $08;
      ACCESS_DELETE  = $10;
      ACCESS_ATRIB   = $20;
      ACCESS_PERM    = $40;
      ACCESS_ALL     = ACCESS_READ or ACCESS_WRITE or ACCESS_CREATE or ACCESS_EXEC or ACCESS_DELETE or ACCESS_ATRIB or ACCESS_PERM;
...
  function NetShareAdd(servername: pWideChar; 
level: DWORD; buf: PBYTE; parm_err: PDWORD): NET_API_STATUS;
                        stdcall; external 'NetAPI32.dll' name 'NetShareAdd';
...
implementation
...
procedure TForm1.Button2Click(Sender: TObject);
var
  AShareInfo : PSHARE_INFO_2;
  parmError  : DWORD;
begin
  CreateDir('D:\test_folder');
  AShareInfo := New(PSHARE_INFO_2);
  try
    with AShareInfo^ do
    begin
      shi2_netname := WideString('Test_sharing');
      shi2_type    := STYPE_DISKTREE;
      shi2_remark  := nil;
      shi2_permissions := ACCESS_ALL;
      shi2_max_uses    := DWORD(-1); // Maximum allowed
      shi2_current_uses:= 0;
      shi2_path        := WideString('D:\test_folder');
      shi2_passwd      := nil;
    end;
    if (NetShareAdd(nil, 2, PBYTE(AShareInfo), @parmError) <> NERR_SUCCESS)then
     ShowMessage(IntToStr(parmError));
  finally
    FreeMem(AShareInfo, SizeOf(PSHARE_INFO_2));
  end;
end;
...
HTH

--- markus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top