这是迷糊老兄帮我解决的,楼主稍微修改就可以使用了:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
WNetConnectionDialog(handle,RESOURCETYPE_DISK);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if WNetCancelConnection2(pchar('x:'),0,false)=NO_ERROR then
Application.MessageBox('X: 断开成功','提示')
else Application.MessageBox('X: 断开失败','提示')
end;
procedure TForm1.Button3Click(Sender: TObject);
function AddShareDriver(localname,remotename,username,password:string):boolean;
var
NetSource : TNetResource;
begin
with NetSource do
begin
dwType := RESOURCETYPE_disk;
lpLocalName :=pchar(localname);
lpRemoteName :=pchar(remotename);
lpProvider :='';
end;
result:=WnetAddConnection2(NetSource,pchar(password),pchar(username),CONNECT_UPDATE_PROFILE)=NO_ERROR;
end;
begin
if AddShareDriver('X:','//172.16.5.2/f','temp','') then
Application.MessageBox('X:=172.16.5.2/f,映射成功!','提示')
else Application.MessageBox('X:=172.16.5.2/f,映射失败!','提示')
end;
end.