1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
type
_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;
PSHARE_INFO_2= ^_SHARE_INFO_2;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
Share: PSHARE_INFO_2;
ParamErr: lpdword;
Rep : longint;
const
STYPE_DISKTREE = 0;
STYPE_PRINTQ = 1;
STYPE_DEVICE = 2;
STYPE_IPC = 3;
STYPE_DFS = 100;
STYPE_SPECIAL = $80000000;
ACCESS_NONE = 0;
ACCESS_READ = 1;
ACCESS_WRITE = 2;
ACCESS_CREATE = 4;
ACCESS_EXEC = 8;
ACCESS_DELETE = 16;
ACCESS_ATRIB = 32;
ACCESS_PERM = 64;
ACCESS_ALL = (ACCESS_READ+ACCESS_WRITE+ACCESS_CREATE+ACCESS_EXEC+ACCESS_DELETE+ACCESS_ATRIB+ACCESS_PERM);
implementation
{$R *.dfm}
function NetShareAdd(servername: LPWSTR;
level: DWORD;
buf: pSHARE_INFO_2;
parm_err: LPDWORD):LongWord; stdcall; external 'netapi32.dll';
function NetShareDel(servername: LPWSTR;
netname : LPWSTR;
reserved : DWORD):LongWord; stdcall; external 'netapi32.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
new(share);
Share^.shi2_netname := 'TESTSHARE'; //nom de partage du dossier
Share^.shi2_type := STYPE_DISKTREE; // disk drive
Share^.shi2_remark := 'TESTSHARE to test NetShareAdd'; // zone commentaire
Share^.shi2_permissions := ACCESS_ALL; //definition des droits
Share^.shi2_max_uses := 4; // nb max de users simultane
Share^.shi2_current_uses := 0;
Share^.shi2_path := 'C:\essai'; //ici le chemin du dossier a partager
Share^.shi2_passwd := Nil; // nil si pas password
rep := NetShareAdd(nil, 2, SHARE, ParamErr);
if rep = 0 then
messagedlg('OK Dossier partagé',mtInformation,[mbOK], 0)
else
messagedlg(inttostr(rep) + ' - ' +SysErrorMessage(rep),mtWarning, [mbOK], 0);
dispose(share);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i : integer;
begin
i := 0;
rep := NetShareDel(nil, 'TESTSHARE', 0);
if rep = 0 then
messagedlg('OK Dossier départagé',mtInformation,[mbOK], 0)
else
messagedlg(inttostr(rep) + ' - ' +SysErrorMessage(rep),mtWarning, [mbOK], 0);
end;
end. |
Partager