unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls,AccCtrl;<br><br>type<br> TForm1 = class(TForm)<br> Edit1: TEdit;<br> Edit2: TEdit;<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br> TSHARE_INFO_502 = record<br> shi502_netname: PWideChar;<br> shi502_type: DWORD;<br> shi502_remark: PWideChar;<br> shi502_permissions: DWORD;<br> shi502_max_uses: DWORD;<br> shi502_current_uses: DWORD;<br> shi502_path: PWideChar;<br> shi502_passwd: PWideChar;<br> shi502_reserved: DWORD;<br> shi502_security_descriptor: PSECURITY_DESCRIPTOR;<br> end;<br><br> PBYTE = ^BYTE;<br> PDWORD = ^DWORD;<br>function NetShareAdd(servername:Widestring; level: DWORD; buf: PBYTE;<br> VAR parm_err: LPDWORD ): DWORD; stdcall;<br>var<br> Form1: TForm1;<br><br>implementation<br><br>function NetShareAdd; external 'netapi32.DLL' name 'NetShareAdd';<br>function NetShareDel(ServerName:Widestring; NetName: Widestring;<br> Reserved: DWord): Integer; StdCall;external 'netapi32.dll' name 'NetShareDel';<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> ServerName:widestring;<br> si: TSHARE_INFO_502;<br> r: DWORD;<br> parm_err:LPDword;<br>begin<br> si.shi502_netname := 'temp4'; // 共享名称<br> si.shi502_type := 0; //STYPE_DISKTREE<br> si.shi502_remark := nil;<br> si.shi502_max_uses := $FFFFFFFF;<br> si.shi502_current_uses := 10;<br> si.shi502_path := 'e:/sql'; //你要共享的路径<br> si.shi502_passwd := nil;<br> si.shi502_reserved := 0;<br> si.shi502_security_descriptor := nil;<br> si.shi502_permissions:=TRUSTEE_ACCESS_ALL;<br> ServerName:='ricky'; // 你要共享的电脑名称<br> try<br> r := NetShareAdd(ServerName, 502, @si, parm_err );<br> Finally<br><br> end;<br><br> Edit1.Text := Format( '%d', [r] ); // 0表示成功,53表示不成功<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br> ServerName, netname:widestring;<br>begin<br> netname := 'temp4';<br> ServerName:='ricky'; // 你要共享的电脑名称<br> try<br> NetShareDel(ServerName,netname,0);<br> Finally<br> end;<br>end;<br><br>end.<br>