| |

VerySource

 Forgot password?
 Register
Search
View: 2757|Reply: 11

Super difficult question: How to share a folder and then set the sharing permissions of the shared folder?

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-8 05:30:01
| Show all posts |Read mode
How to share a folder, and then set the sharing permissions of the shared folder?

It's better to have test code.
Thank you! !! !!
Reply

Use magic Report

0

Threads

22

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-3-31 19:45:02
| Show all posts
unit My_Share;
    
  interface
  uses
        SysUtils;
  type
      Share_Info50 = packed record
          shi50_netname: array [0..12] of Char; {13}
          shi50_type: Byte;
          shi50_flags: Word;
          shi50_remark: PChar;
          shi50_path: PChar;
          shi50_rw_password: array [0..8] of Char; {9}
          shi50_ro_password: array [0..8] of Char;
      end;
  const
      STYPE_DISKTREE = 0; {disk share}
      STYPE_PRINTQ = 1; {printer sharing}
    
    
      SHI50F_RDONLY = 1; {Read Only Share}
      SHI50F_FULL = 2; {Full Share}
      SHI50F_DEPENDSON = (SHI50F_RDONLY or SHI50F_FULL); {password required for entry}
    
      SHI50F_PERSIST = 256; {This option: Only effective after the computer restarts}
      SHI50F_SYSTEM = 512; {This option: take effect immediately, and right-click cannot see the share}
  function ShareResource (ServerName: PChar; FilePath: PChar;
      NetName: PChar; Remark: PChar;
      ShareType: Byte; Flags: Word;
      RWPass: PChar; ROPass: PChar): Integer;
      function DeleteShare (ServerName: PChar; NetName: PChar): Integer;
  function NetShareAdd (ServerName: PChar; ShareLevel: SmallInt; Buffer: Pointer; Size: Word): Integer; StdCall;
  function NetShareDel (ServerName: PChar; NetName: PChar; Reserved: Word): Integer; StdCall;
    
  implementation
    
  function ShareResource (ServerName: PChar; FilePath: PChar;
      NetName: PChar; Remark: PChar;
      ShareType: Byte; Flags: Word;
      RWPass: PChar; ROPass: PChar): Integer; {Catalog sharing}
  var
      MyShare: Share_Info50;
      PMyShare: ^ Share_Info50;
  begin
      strLcopy (MyShare.shi50_netname, NetName, 13);
      MyShare.shi50_type: = ShareType;
      MyShare.shi50_flags: = Flags;
      MyShare.shi50_remark: = Remark;
      MyShare.shi50_path: = FilePath;
      strLcopy (MyShare.shi50_rw_password, RWPass, 9);
      strLcopy (MyShare.shi50_ro_password, ROPass, 9);
      PMyShare: = @MyShare;
      Result: = NetShareAdd (ServerName, 50, PMyShare, SizeOf (MyShare));
  end;
    
  function DeleteShare (ServerName: PChar; NetName: PChar): Integer; {Undo share directory}
  begin
      Result: = NetShareDel (ServerName, NetName, 0);
  end;
    
  function NetShareAdd; external 'SVRAPI.DLL';
  function NetShareDel; external 'SVRAPI.DLL'; {Note: To change to NETAPI32.DLL under NT / 2000, you can judge the system to load different DLLs in the program}
  end.
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-4-3 13:45:01
| Show all posts
It looks wrong upstairs
NetShareAdd (ServerName, 50, PMyShare, SizeOf (MyShare));
It seems that there are only two kinds.
Value Meaning
2 The buf parameter points to an array of SHARE_INFO_2 structures.
502 The buf parameter points to an array of SHARE_INFO_502 structures.
And yours is just the code for the shared folder, and is there no setting for sharing access
Reply

Use magic Report

0

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-4 19:45:01
| Show all posts
The landlord misunderstood,
level refers to the type used
When level is 2, buf uses SHARE_INFO_2 structures.
When the level is 502, buf uses SHARE_INFO_502 structures.

And you can set permissions, SHARE_INFO_502.shi502_permissions is to set permissions, including the following permissions:
ACCESS_READ Permission to read data from a resource and, by default, to execute the resource.
ACCESS_WRITE Permission to write data to the resource.
ACCESS_CREATE Permission to create an instance of the resource (such as a file); data can be written to the resource as the resource is created.
ACCESS_EXEC Permission to execute the resource.
ACCESS_DELETE Permission to delete the resource.
ACCESS_ATRIB Permission to modify the resource's attributes (such as the date and time when a file was last modified).
ACCESS_PERM Permission to modify the permissions (read, write, create, execute, and delete) assigned to a resource for a user or application.
ACCESS_ALL Permission to read, write, create, execute, and delete resources, and to modify their attributes and permissions.
Reply

Use magic Report

0

Threads

25

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-4-4 23:30:02
| Show all posts
shi_permissions

Value
ACCESS_READ
ACCESS_WRITE
ACCESS_CREATE
ACCESS_EXEC
ACCESS_DELETE
ACCESS_ATRIB
ACCESS_PERM
ACCESS_ALL
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-17 18:15:01
| Show all posts
What should I do if I want to specify the shared user?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-17 19:15:01
| Show all posts
There should be related API landlords to check. . .
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-19 11:30:01
| Show all posts
From another perspective, wouldn’t it be better to modify the registry directly? But which registry should be modified?
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-19 11:45:01
| Show all posts
Registry path
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-19 12:00:01
| Show all posts
Download a control, everything is done. Sharing v3.0
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list