Después de varios intentos lo conseguí con este código, lo publico por si alguien tiene el mismo problema.
Código Delphi
[-]procedure Conect;
var
NetResource: TNETRESOURCE;
begin
ZeroMemory(@NetResource, sizeof(TNETRESOURCE));
NetResource.dwType:= RESOURCETYPE_ANY;
NetResource.lpLocalName:= 'Z:';
NetResource.lpRemoteName:= '\\ruta'; NetResource.lpProvider:= '';
if NO_ERROR <> WNetAddConnection2(NetResource, 'PassWord', 'UserName', CONNECT_UPDATE_PROFILE) then
begin
end;
WNetCancelConnection2('Z:', CONNECT_UPDATE_PROFILE, true); end;