unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
netresource:Tnetresource;
re:dword;
begin
netresource.dwScope:=RESOURCE_GLOBALNET;
netresource.dwUsage:=RESOURCEUSAGE_CONNECTABLE;
netresource.dwType:=RESOURCETYPE_DISK;
netresource.dwDisplayType:=RESOURCEDISPLAYTYPE_SERVER;
netresource.lpLocalName:='';
netresource.lpRemoteName:='//server_name';
netresource.lpProvider:='';
re:=WNetAddConnection3(
application.Handle,
netresource,
'password',
'username',
CONNECT_UPDATE_PROFILE
);
if re=NO_ERROR then
begin
showmessage('ok');
end
else begin
application.MessageBox('无法连接到服务器,请与系统管理员联系','系统提示',mb_ok);
application.Terminate;
end;
end;