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 := ''\\MyServer\MyDirectory'';
// 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;