IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Web & réseau Delphi Discussion :

[WNetAddConnection2] Comment fermer une connection ?


Sujet :

Web & réseau Delphi

  1. #1
    Membre régulier Avatar de souch
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    145
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juin 2003
    Messages : 145
    Points : 124
    Points
    124
    Par défaut [WNetAddConnection2] Comment fermer une connection ?


    Grace a un WNetAddConnection2 avec comme paramettre lpnet ceci
    lpNetRessource.dwType:=RESOURCETYPE_ANY;
    je me loggue sur un partage réseau d'une machine distante, sans pour autant monter un lecteur réseau.
    La connection est bien créé, par la suite j'ai donc access au partage.

    Mon probleme vien du fait que je ne parvient pas a fermer cette connection, a me délogger ...

    WNetCancelConnection2 attent pour paramettre une lettre de lecteur, comment faire dans mon cas ?

    Mon appli lance pas mal de connection, et il semble que windows n'accepte qu'un certain nombre, donc j'ai des erreurs ....

    une idée ?

    si vous voullez + de détails, n'hesitez pas !

    vala le code de connection complet, je pense qu'il servira a d'autres :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
     
    function TForm1.ConnecterLecteurReseau(Serveur:pchar;PartageServeur:pchar;
                                    codeUtilisateur:pchar;motpasseUtilisateur:pchar): boolean;
    var lpNetRessource:TNetResource;
        Resultat:DWord;
        tampon,erreur:string;
    begin
     
      lpNetRessource.dwType:=RESOURCETYPE_ANY;
      lpNetRessource.lpLocalName:='';
      tampon  := '\\'+ Serveur + '\' + PartageServeur ;
      lpNetRessource.lpRemoteName:= pchar(tampon);
      lpNetRessource.lpProvider:=nil;
      Resultat:=WNetAddConnection2(lpNetRessource,MotPasseUtilisateur,codeUtilisateur,0);
     
      if (Resultat<>NO_ERROR) OR (Resultat<>ERROR_SESSION_CREDENTIAL_CONFLICT) then Result:=False;
     
      case resultat of
     
        NO_ERROR :Result:=True;
        ERROR_SESSION_CREDENTIAL_CONFLICT  : begin
          erreur:='ERROR_SESSION_CREDENTIAL_CONFLICT'+#13+'Vous êtes peut être déja loggé ?';
          Result:= true ;
        end;
     
        ERROR_ACCESS_DENIED     : erreur:='Accès refusé';
        ERROR_ALREADY_ASSIGNED  : erreur:='Lecteur réseau déjà attribué';
        ERROR_INVALID_PASSWORD  : erreur:='Mot de passe incorrect';
        ERROR_BAD_NET_NAME      : erreur:='Erreur de connexion à votre répertoire réseau (nom réseau)';
        ERROR_LOGON_FAILURE     : erreur:='ERROR_LOGON_FAILURE';
        ERROR_NOT_READY         : erreur:='ERROR_NOT_READY';
        ERROR_NOT_DOS_DISK      : erreur:='ERROR_NOT_DOS_DISK';
        ERROR_READ_FAULT        : erreur:='ERROR_READ_FAULT';
        ERROR_SHARING_VIOLATION : erreur:='ERROR_SHARING_VIOLATION';
        ERROR_NOT_SUPPORTED     : erreur:='ERROR_NOT_SUPPORTED';
        ERROR_NETWORK_BUSY      : erreur:='ERROR_NETWORK_BUSY';
        ERROR_DEV_NOT_EXIST     : erreur:='ERROR_DEV_NOT_EXIST';
        ERROR_NETNAME_DELETED   : erreur:='ERROR_NETNAME_DELETED';
        ERROR_NETWORK_ACCESS_DENIED : erreur:='ERROR_NETWORK_ACCESS_DENIED';
        ERROR_TRUST_FAILURE     : erreur:='ERROR_TRUST_FAILURE';
        ERROR_FILE_NOT_FOUND    : erreur:='The system cannot find the file specified.';
        ERROR_PATH_NOT_FOUND    : erreur:='The system cannot find the path specified.';
        ERROR_TOO_MANY_OPEN_FILES : erreur:='The system cannot open the file.';
        ERROR_INVALID_HANDLE    : erreur:='The handle is invalid.';
        ERROR_ARENA_TRASHED     : erreur:='The storage control blocks were destroyed.';
        ERROR_NOT_ENOUGH_MEMORY : erreur:='Not enough storage is available to process this command.';
        ERROR_INVALID_BLOCK     : erreur:='The storage control block address is invalid.';
        ERROR_BAD_ENVIRONMENT   : erreur:='The environment is incorrect.';
        ERROR_BAD_FORMAT        : erreur:='An attempt was made to load a program with an incorrect format.';
        ERROR_INVALID_ACCESS    : erreur:='The access code is invalid.';
        ERROR_INVALID_DATA      : erreur:='The data is invalid.';
        ERROR_OUTOFMEMORY       : erreur:='Not enough storage is available to complete the operation.';
        ERROR_INVALID_DRIVE     : erreur:='The system cannot find the drive specified.';
        ERROR_CURRENT_DIRECTORY : erreur:='The directory cannot be removed.';
        ERROR_NOT_SAME_DEVICE   : erreur:='The system cannot move the file to a different disk drive.';
        ERROR_NO_MORE_FILES     : erreur:='There are no more files.';
        ERROR_WRITE_PROTECT     : erreur:='Error, The write protect is set';
        ERROR_BAD_UNIT          : erreur:='Error, The system cannot find the device';
        ERROR_BAD_COMMAND       : erreur:='The device does not recognize the command.';
        ERROR_CRC               : erreur:='Data error (cyclic redundancy check).';
        ERROR_BAD_LENGTH        : erreur:='Incorrect command length from program';
        ERROR_SEEK              : erreur:='The drive cannot locate a specfic area or track on the disk';
        ERROR_SECTOR_NOT_FOUND  : erreur:='The drive cannot find the sector requested.';
        ERROR_OUT_OF_PAPER      : erreur:='The Printer is out of paper.';
        ERROR_WRITE_FAULT       : erreur:='The system cannot read from the specified device.';
        ERROR_GEN_FAILURE       : erreur:='A device attached to the system is not functioning.';
        ERROR_LOCK_VIOLATION    : erreur:='Another process has locked the file.';
        ERROR_WRONG_DISK        : erreur:='The wrong diskette is in the drive.';
        ERROR_SHARING_BUFFER_EXCEEDED  : erreur:='Too many files opened for sharing.';
        ERROR_HANDLE_EOF        : erreur:='Reached end of file';
        ERROR_HANDLE_DISK_FULL  : erreur:='The disk is full';
        ERROR_MORE_DATA         : erreur:='More data is available';
        ERROR_END_OF_MEDIA      : erreur:='Error, End of media';
        ERROR_FILEMARK_DETECTED : erreur:='Error, Filemark detected';
        ERROR_BEGINNING_OF_MEDIA: erreur:='Error, Cannot access data before medium marker';
        ERROR_SETMARK_DETECTED  : erreur:='Error, A setmark was reached';
        ERROR_NO_DATA_DETECTED  : erreur:='Error, Eof of data marker reached';
        ERROR_PARTITION_FAILURE       : erreur:='Error, The tape could not be partitioned';
        ERROR_INVALID_BLOCK_LENGTH    : erreur:='Error, The Block size is incorrect';
        ERROR_DEVICE_NOT_PARTITIONED  : erreur:='Error, Partition information not found';
        ERROR_UNABLE_TO_LOCK_MEDIA    : erreur:='Error, An attempt to lock the ejection mechanism failed';
        ERROR_UNABLE_TO_UNLOAD_MEDIA  : erreur:='Error, An attempt to unload the media failed';
        ERROR_MEDIA_CHANGED           : erreur:='Error, The tape in the drive has been replaced.' +
         'This tape drive may be type QIC which is not supported.';
        ERROR_BUS_RESET               : erreur:='Error, A reset condition was detected on the bus';
        ERROR_NO_MEDIA_IN_DRIVE       : erreur:='There is no media in the drive';
        ERROR_BAD_DEVICE              : erreur:='ERROR_BAD_DEVICE';
        ERROR_BAD_NETPATH             : erreur:='ERROR_BAD_NETPATH';
        ERROR_BAD_DEV_TYPE            : erreur:=' ERROR_BAD_DEV_TYPE';
        ERROR_REQ_NOT_ACCEP           : erreur:='ERROR_REQ_NOT_ACCEP';
      end;
     
      if Result=False then begin
        Form1.Memo1.Lines.Add(erreur+'('+intToStr(Resultat)+')');
        ShowMessage(erreur+'('+intToStr(Resultat)+')');
      end;
     
    End;
    j'ai codé pas mal d'erreur possibles, mai il en manque encore qqs unes ...

  2. #2
    Expert confirmé
    Avatar de anapurna
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2002
    Messages
    3 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Mai 2002
    Messages : 3 435
    Points : 5 848
    Points
    5 848
    Par défaut
    salut


    si tu n'a pas de localname utilise le remotename

    exemple
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    if Trim(FLocalName) <> '' then
        strDevice := FLocalName
      else
        strDevice := FRemoteName;
     
      if WNetCancelConnection2(PChar(strDevice), CONNECT_UPDATE_PROFILE, AForce)
          <> NO_ERROR then
        raise EDisconnectError.Create('ERROR: deconnexion impossible');
    @+ Phil

  3. #3
    Membre régulier Avatar de souch
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    145
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juin 2003
    Messages : 145
    Points : 124
    Points
    124
    Par défaut
    Merci, je venait d'essayer avec le remottename (\\serveur\partage$) et jusqua présent, pas d'erreurs

    thx pour la réponse

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    298
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 298
    Points : 318
    Points
    318
    Par défaut
    A vérifier, mais je pense que dans l'API Windows tu as une fonction pour convertir le numéro d'erreur en chaine de caractères au lieu de faire un case de 3 pages.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. comment fermer une fenetre enfant
    Par stefane1981 dans le forum MFC
    Réponses: 12
    Dernier message: 20/10/2005, 11h32
  2. Comment fermer une popup après un certains temps ?
    Par magic8392 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 19/10/2005, 12h06
  3. Comment fermer une fenêtre enfant MDI ?
    Par DeveloMagaly dans le forum Composants VCL
    Réponses: 2
    Dernier message: 30/09/2005, 13h10
  4. Comment fermer une Fenetre Modal avec Code ?
    Par Soulama dans le forum Langage
    Réponses: 19
    Dernier message: 13/07/2005, 11h17
  5. Comment fermer une fenêtre quand la souris et clavier sont inactifs ?
    Par Goldenkiller dans le forum Composants VCL
    Réponses: 7
    Dernier message: 06/12/2004, 22h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo