求删除共享的方法!! (100分)

  • 主题发起人 主题发起人 carem1
  • 开始时间 开始时间
C

carem1

Unregistered / Unconfirmed
GUEST, unregistred user!
我知道netaharedel可以删除共享,<br>&nbsp;function &nbsp;NetShareDel(<br>&nbsp; &nbsp; ServerName :string;<br>&nbsp; &nbsp; LPTSTR :string;<br>&nbsp; &nbsp; DWORD :integer):Cardinal; stdcall; external 'netapi32.dll' name 'NetSharedel';<br><br>但是谁可以举一个具体的例子给我??我发现使用的过程中好像要用到指针,我没用过
 
删除本机上的共享用:<br>netsharedel(nil, '共享名',0);<br>或:<br>var sharename : string;<br><br>netsharedel(nil, pchar(sharename), 0);
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls,AccCtrl;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Edit1: TEdit;<br>&nbsp; &nbsp; Edit2: TEdit;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>&nbsp; TSHARE_INFO_502 = record<br>&nbsp; &nbsp; shi502_netname: PWideChar;<br>&nbsp; &nbsp; shi502_type: DWORD;<br>&nbsp; &nbsp; shi502_remark: PWideChar;<br>&nbsp; &nbsp; shi502_permissions: DWORD;<br>&nbsp; &nbsp; shi502_max_uses: DWORD;<br>&nbsp; &nbsp; shi502_current_uses: DWORD;<br>&nbsp; &nbsp; shi502_path: PWideChar;<br>&nbsp; &nbsp; shi502_passwd: PWideChar;<br>&nbsp; &nbsp; shi502_reserved: DWORD;<br>&nbsp; &nbsp; shi502_security_descriptor: PSECURITY_DESCRIPTOR;<br>&nbsp; end;<br><br>&nbsp; PBYTE = ^BYTE;<br>&nbsp; PDWORD = ^DWORD;<br>function NetShareAdd(servername:Widestring; level: DWORD; buf: PBYTE;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VAR &nbsp;parm_err: LPDWORD ): DWORD; stdcall;<br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>function NetShareAdd; external 'netapi32.DLL' name 'NetShareAdd';<br>function NetShareDel(ServerName:Widestring; NetName: Widestring;<br>&nbsp; &nbsp; &nbsp;Reserved: DWord): Integer; StdCall;external 'netapi32.dll' name 'NetShareDel';<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; ServerName:widestring;<br>&nbsp; si: TSHARE_INFO_502;<br>&nbsp; r: DWORD;<br>&nbsp; parm_err:LPDword;<br>begin<br>&nbsp; si.shi502_netname := 'temp4'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 共享名称<br>&nbsp; si.shi502_type := 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //STYPE_DISKTREE<br>&nbsp; si.shi502_remark := nil;<br>&nbsp; si.shi502_max_uses := $FFFFFFFF;<br>&nbsp; si.shi502_current_uses := 10;<br>&nbsp; si.shi502_path := 'e:/sql'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//你要共享的路径<br>&nbsp; si.shi502_passwd := nil;<br>&nbsp; si.shi502_reserved := 0;<br>&nbsp; si.shi502_security_descriptor := nil;<br>&nbsp; si.shi502_permissions:=TRUSTEE_ACCESS_ALL;<br>&nbsp; ServerName:='ricky'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;你要共享的电脑名称<br>&nbsp; try<br>&nbsp; &nbsp; r := NetShareAdd(ServerName, 502, @si, parm_err );<br>&nbsp; Finally<br><br>&nbsp; end;<br><br>&nbsp; Edit1.Text := Format( '%d', [r] ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp;0表示成功,53表示不成功<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br>&nbsp; ServerName, netname:widestring;<br>begin<br>&nbsp; netname := 'temp4';<br>&nbsp; ServerName:='ricky'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;你要共享的电脑名称<br>&nbsp; try<br>&nbsp; &nbsp;NetShareDel(ServerName,netname,0);<br>&nbsp; Finally<br>&nbsp; end;<br>end;<br><br>end.<br>
 
接受答案了.
 

Similar threads

I
回复
0
查看
573
import
I
I
回复
0
查看
603
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部