局域网内可以用下面的函数:
function AddConnection(const RemoteName, LocalName, UserName, Password: string): DWORD;
var
NetResource: TNetResource;
begin
FillChar(NetResource, SizeOf(NetResource), 0);
with NetResource do
begin
dwType := RESOURCETYPE_ANY;
lpLocalName := PChar(LocalName);
lpRemoteName := PChar(RemoteName);
end;
Result := WNetAddConnection2(NetResource, PChar(Password), PChar(UserName), 0);
end;
这样调用: AddConnection('//server1/fsr60','M:',MyName, MyPassWord);
返回值请看 SDK 中对 WNetAddConnection2 的说明。