Map or unmap a network disk at run-time

uses
Windows;
var
nw: TNetResource;
errCode : DWord;
begin
nw.dwType := RESOURCETYPE_DISK;
nw.lpLocalName := nil;
nw.lpRemoteName := PChar('\\the_fileserver\C$');
nw.lpProvider := nil;
nw.lpLocalName := 'R:';
errCode := WNetAddConnection2(nw, {password}nil, {user name}nil, 0);
if errCode = NO_ERROR then
begin
ShowMessage('The disk is mapped as R:');
end;
end;