程序代碼如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TfrmMain = class(TForm)
btnConnect: TButton;
btnDisconnect: TButton;
edtLocal: TEdit;
Label1: TLabel;
Label2: TLabel;
edtRemote: TEdit;
procedure btnConnectClick(Sender: TObject);
procedure btnDisconnectClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
procedure TfrmMain.btnConnectClick(Sender: TObject);
var
NetShare :NETRESOURCE;
begin
NetShare.dwType := RESOURCETYPE_DISK;
NetShare.lpLocalName := PAnsiChar(edtLocal.Text);
NetShare.lpRemoteName := PAnsiChar(edtRemote.Text);
NetShare.lpProvider :=’’;
WNetAddConnection2(NetShare, ’’, ’’, CONNECT_UPDATE_PROFILE);
end;
procedure TfrmMain.btnDisconnectClick(Sender: TObject);
var
strLocalName : PChar;
begin
strLocalName:=PAnsiChar(edtLocal.Text);
WNetCancelConnection2(strLocalName,CONNECT_UPDATE_PROFILE,False);
end;
end.