Search code examples
delphiwinapidelphi-7shareunc

Sharing a folder programmatically and revoking it. (Delphi 7)


  1. How does one programmatically create a UNC share from a known directory?
  2. How does one revoke it programmatically?

I don't want the user to fiddle with the Share dialog. Additional info such as changing the share name, comment, user limit is also welcomed.

Thanks SoulBlade (Using Delphi 7)


Solution

  • Create the share with NetShareAdd. This will share the directory with a null ACL, which is equavalent to allowing everyone full access.

    Delete the share with NetShareDel.

    Madshi's MadSecurity package has a helper which simplifies this down to:

    NewShare(path, shareName, remark);
    Share(shareName).Delete;