procedure TForm1.FormCreate(Sender: TObject);
var
netresource:Tnetresource;
re:dword;
begin
winexec('net use * /delete',0);
WNetCancelConnection2(
'//servername',
CONNECT_UPDATE_PROFILE,
true);
netresource.dwScope:=RESOURCE_GLOBALNET;
netresource.dwUsage:=RESOURCEUSAGE_CONNECTABLE;
netresource.dwType:=RESOURCETYPE_DISK;
netresource.dwDisplayType:=RESOURCEDISPLAYTYPE_SERVER;
netresource.lpLocalName:='';
netresource.lpRemoteName:='//servername;
netresource.lpProvider:='';
re:=WNetAddConnection3(
application.Handle,
netresource,
'password',
'username',
CONNECT_UPDATE_PROFILE
);
if re=NO_ERROR then
begin
end
else begin
application.MessageBox('无法连接到服务器,请与系统管理员联系','系统提示',mb_ok);
application.Terminate;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
WNetCancelConnection2(
'//servername',
CONNECT_UPDATE_PROFILE,
true);
form1.Release;
end;
[blue]最好将共享的目录名称加上$,例如:共享名 dir$[/blue]
直接操作//servername/dir$就可以了!!!!!!!!!!!!