我做了两个函数能构建立与断开网络上的映射盘符,代码如下(
其中用到的API与TNetResource类在Windows单元中有函数原型):
function Mapping(const ARemoteName, AUserName, APassword, ALocalName : String): Boolean;
var
NetResource : TNetResource;
begin
NetResource.dwType := RESOURCETYPE_DISK;
NetResource.lpLocalName := Pchar(ALocalName);
NetResource.lpRemoteName := Pchar(ARemoteName);
NetResource.lpProvider := '';
if WnetAddConnection2(NetResource, Pchar(APassword),
Pchar(AUserName), CONNECT_UPDATE_PROFILE)
= NO_ERROR then
result := True
else
result := False;
end;
function DisMapping(const ALocalName : String): Boolean;
begin
if WNetCancelConnection2(Pchar(ALocalName), CONNECT_UPDATE_PROFILE, True)
= NO_ERROR then
result := True
else result := False;
end;