function WNetAddConnection2W(var lpNetResource: TNetResourceW;lpPassword, lpUserName: PWideChar; dwFlags: DWORD): DWord; stdcall;
首先要填一個 lpNetResource structure,然後 passWord,user name, 和一個標志表明是否這個映射每次登錄時都要還原。詳情見幫助。
var
NRW: TNetResource;
begin
with NRW do begin dwType := RESOURCETYPE_ANY;
lpLocalName := 'X:'; // map to this driver letter
lpRemoteName := 'MyServerMyDirectory';
// Must be filled in. If an empty string is used,
// it will use the lpRemoteName. lpProvider := ''; end;
WNetAddConnection2(NRW, 'MyPassWord', 'MyUserName', CONNECT_UPDATE_PROFILE);
end;