浪
浪漫龙影
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Mask;
type
TfrmMain = class(TForm)
edtResource: TEdit;
edtLocal: TEdit;
StaticText1: TStaticText;
StaticText2: TStaticText;
Panel1: TPanel;
Bevel1: TBevel;
edtUser: TEdit;
StaticText3: TStaticText;
StaticText4: TStaticText;
edtPass: TMaskEdit;
Panel2: TPanel;
Bevel2: TBevel;
btnMap: TButton;
btnCancelMap: TButton;
btnExit: TButton;
procedure btnMapClick(Sender: TObject);
procedure btnCancelMapClick(Sender: TObject);
procedure btnExitClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.DFM}
procedure TfrmMain.btnCancelMapClick(Sender: TObject);
begin
if MessageDlg('确实要断开么?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
//不管是否有文件打开,断开网络驱动器:
if WNetCancelConnection2(pchar(edtLocal.text), CONNECT_UPDATE_PROFILE, True)=NO_ERROR then
//映射断开成功
showmessage(edtResource.text+'映射断开!')
else
showmessage('断开映射失败');
end;
procedure TfrmMain.btnMapClick(Sender : TObject);
var
NetSource : TNetResource;
begin
with NetSource do
begin
dwType := RESOURCETYPE_DISK;
lpLocalName :=Pchar(edtLocal.text);
// 将远程资源映射到此驱动器
lpRemoteName :=pchar(edtResource.text);
// 远程网络资源
lpProvider := '';
// 必须赋值,如为空则使用lpRemoteName的值
end;
if WnetAddConnection2(NetSource, pchar(edtPass.text), pchar(edtUser.text), CONNECT_UPDATE_PROFILE)=NO_ERROR
//用户名为Guest,口令为Password,下次登录时重新连接,此时在Windows资源管理器中可看到网络驱动器:
then
//映射成功
showmessage(edtResource.text+'成功映射成'+edtLocal.text)
else
showmessage('映射失败!');
end;
procedure TfrmMain.btnExitClick(Sender: TObject);
begin
frmMain.Close;
end;
end.
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Mask;
type
TfrmMain = class(TForm)
edtResource: TEdit;
edtLocal: TEdit;
StaticText1: TStaticText;
StaticText2: TStaticText;
Panel1: TPanel;
Bevel1: TBevel;
edtUser: TEdit;
StaticText3: TStaticText;
StaticText4: TStaticText;
edtPass: TMaskEdit;
Panel2: TPanel;
Bevel2: TBevel;
btnMap: TButton;
btnCancelMap: TButton;
btnExit: TButton;
procedure btnMapClick(Sender: TObject);
procedure btnCancelMapClick(Sender: TObject);
procedure btnExitClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.DFM}
procedure TfrmMain.btnCancelMapClick(Sender: TObject);
begin
if MessageDlg('确实要断开么?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
//不管是否有文件打开,断开网络驱动器:
if WNetCancelConnection2(pchar(edtLocal.text), CONNECT_UPDATE_PROFILE, True)=NO_ERROR then
//映射断开成功
showmessage(edtResource.text+'映射断开!')
else
showmessage('断开映射失败');
end;
procedure TfrmMain.btnMapClick(Sender : TObject);
var
NetSource : TNetResource;
begin
with NetSource do
begin
dwType := RESOURCETYPE_DISK;
lpLocalName :=Pchar(edtLocal.text);
// 将远程资源映射到此驱动器
lpRemoteName :=pchar(edtResource.text);
// 远程网络资源
lpProvider := '';
// 必须赋值,如为空则使用lpRemoteName的值
end;
if WnetAddConnection2(NetSource, pchar(edtPass.text), pchar(edtUser.text), CONNECT_UPDATE_PROFILE)=NO_ERROR
//用户名为Guest,口令为Password,下次登录时重新连接,此时在Windows资源管理器中可看到网络驱动器:
then
//映射成功
showmessage(edtResource.text+'成功映射成'+edtLocal.text)
else
showmessage('映射失败!');
end;
procedure TfrmMain.btnExitClick(Sender: TObject);
begin
frmMain.Close;
end;
end.