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 :

[Réseaux] Comment faire un Net Use en Delphi ?


Sujet :

Web & réseau Delphi

  1. #1
    Membre à l'essai
    Inscrit en
    Avril 2004
    Messages
    11
    Détails du profil
    Informations forums :
    Inscription : Avril 2004
    Messages : 11
    Points : 10
    Points
    10
    Par défaut [Réseaux] Comment faire un Net Use en Delphi ?
    Bonjour , voila mon probleme sur lequel je bute depuis maintenant une semaine .
    J'ai besoin de faire un simple net use de la machine A a la machine B sur un réseau local .Je me sers donc de WnetAddConnection et WnetAddConnection2 , cela marche tres bien si le net use a faire est de la forme:
    Net use \\NomDuPc\IPC$ "password" "/u:username"

    mais lorsque le net use est de la forme
    Net use \\NomDuPc\IPC$ "password" "/u:NomDuPc\username"

    alors là , impossible de faire quoi que ce soit
    en remplacant l username par NomDuPc\username , j ai droit a ca :
    Logon failure: unknown user name or bad password

    et si je laisse l username sans NomDuPc ,j obtien la meme erreur que si je faisé un net use avec "/u:username" a savoir l erreur 1312
    "A specified logon session does not exist. It may already have been terminated."

    Je pense donc qu il me manque juste de savoir comment specifié le "NomDuPc\username"

    J'y passe mes nuits! j ai retourné Google mais sans resultat
    toute aide est la bienvenue

  2. #2
    Nouveau Candidat au Club
    Inscrit en
    Avril 2004
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Avril 2004
    Messages : 1
    Points : 1
    Points
    1
    Par défaut
    Slt,
    Pour ma part, j'ai trouvé il y a qq année cette UNIT qui fonctionne très bien.

    Si cela peut te dépanner !!!
    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
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
     
    -------------------------------------------------------------------------------------
    unit network;
     
    interface
     
    uses Windows;
     
    const
     // exemple, à remplacer, bien sur !!!!
      _NET_LETT_ = 'W:';
      _NET_RESS_ = '\\MACHINE\E$';
      _NET_USER_ = 'DOMAINE\USER';
      _NET_PASS_ = 'PASSWORD';
     
    function ConnectDrive(_handle: HWND; _drvLetter: string; _netPath: string; _user: string; _pass: string; _showError: Boolean; _reconnect: Boolean): DWORD;
    function DisconnectNetDrive(_locDrive: string; _showError: Boolean; _force: Boolean; _save: Boolean): DWORD;
    function NetError(err: DWORD): string;
     
    implementation
     
    { ------------------------------------------------------------------------- }
     
    function ConnectDrive(_handle: HWND; _drvLetter: string; _netPath: string; _user: string; _pass: string; _showError: Boolean; _reconnect: Boolean): DWORD;
    var
      nRes: TNetResource;
      errCode: DWORD;
      dwFlags: DWORD;
     
    begin
      { Fill NetRessource with #0 to provide uninitialized values }
      FillChar(NRes, SizeOf(NRes), #0);
      nRes.dwType := RESOURCETYPE_DISK;
     
      { Set Driveletter and Networkpath }
      nRes.lpLocalName := PChar(_drvLetter);
      nRes.lpRemoteName := PChar(_netPath); { Example: \\Test\C }
     
      { Check if it should be saved for use after restart and set flags }
      if _reconnect then
        dwFlags := CONNECT_UPDATE_PROFILE and CONNECT_INTERACTIVE
      else
        dwFlags := CONNECT_INTERACTIVE;
     
      {errCode := WNetAddConnection3(Form1.Handle, nRes, nil, nil, dwFlags);}
      errCode := WNetAddConnection3(_handle, nRes, PChar(_pass), PChar(_user), dwFlags);
     
      { Show Errormessage, if flag is set }
      if (errCode <> NO_ERROR) and (_showError) then
      begin
        {
        Application.MessageBox(PChar('An error occured while connecting:' + #13#10 +
          SysErrorMessage(GetLastError)),
          'Error while connecting!',
          MB_OK);
        }
      end;
     
      Result := errCode; { NO_ERROR }
    end;
     
    { ------------------------------------------------------------------------- }
     
    function DisconnectNetDrive(_locDrive: string; _showError: Boolean; _force: Boolean; _save: Boolean): DWORD;
    var
      dwFlags: DWORD;
      errCode: DWORD;
     
    begin
      { Set dwFlags, if necessary }
      if _save then
        dwFlags := CONNECT_UPDATE_PROFILE
      else
        dwFlags := 0;
     
      { Cancel the connection }
      errCode := WNetCancelConnection2(PChar(_locDrive), dwFlags, _force);
     
      { Show Errormessage, if flag is set }
      if (errCode <> NO_ERROR) and (_showError) then
      begin
        {
        Application.MessageBox(PChar('An error occured while disconnecting:' + #13#10 +
          SysErrorMessage(GetLastError)),
          'Error while disconnecting',
          MB_OK);
        }
      end;
     
      Result := errCode; { NO_ERROR }
    end;
     
    { ------------------------------------------------------------------------- }
     
    function NetError(err: DWORD): string;
    begin
      case err of
        { Connect }
        ERROR_ACCESS_DENIED: NetError := 'ERROR_ACCESS_DENIED';
        ERROR_ALREADY_ASSIGNED: NetError := 'ERROR_ALREADY_ASSIGNED';
        ERROR_BAD_DEV_TYPE: NetError := 'ERROR_BAD_DEV_TYPE';
        ERROR_BAD_DEVICE: NetError := 'ERROR_BAD_DEVICE';
        ERROR_BAD_NET_NAME: NetError := 'ERROR_BAD_NET_NAME';
        ERROR_BAD_PROFILE: NetError := 'ERROR_BAD_PROFILE';
        ERROR_BAD_PROVIDER: NetError := 'ERROR_BAD_PROVIDER';
        ERROR_BUSY: NetError := 'ERROR_BUSY';
        ERROR_CANCELLED: NetError := 'ERROR_CANCELLED';
        ERROR_CANNOT_OPEN_PROFILE: NetError := 'ERROR_CANNOT_OPEN_PROFILE';
        ERROR_DEVICE_ALREADY_REMEMBERED: NetError := 'ERROR_DEVICE_ALREADY_REMEMBERED';
        ERROR_EXTENDED_ERROR: NetError := 'ERROR_EXTENDED_ERROR';
        ERROR_INVALID_PASSWORD: NetError := 'ERROR_INVALID_PASSWORD';
        ERROR_NO_NET_OR_BAD_PATH: NetError := 'ERROR_NO_NET_OR_BAD_PATH';
        ERROR_NO_NETWORK: NetError := 'ERROR_NO_NETWORK';
     
        { DisConnect }
        ERROR_DEVICE_IN_USE: NetError := 'ERROR_DEVICE_IN_USE';
        ERROR_NOT_CONNECTED: NetError := 'ERROR_NOT_CONNECTED';
        ERROR_OPEN_FILES: NetError := 'ERROR_OPEN_FILES';
      else
        NetError := 'Erreur Inconnu';
      end;
    end;
     
    { ----------------------------------------------------------------------- }
    { ----------------------------------------------------------------------- }
     
    end.
    -------------------------------------------------------------------------------------
    @+
    Eric

    Balises de code ajoutées par Pierre Castelain.
    Pensez-y à l'avenir.

  3. #3
    Membre à l'essai
    Inscrit en
    Avril 2004
    Messages
    11
    Détails du profil
    Informations forums :
    Inscription : Avril 2004
    Messages : 11
    Points : 10
    Points
    10
    Par défaut
    Impeccable

    un enorrrrrme merci a toi !!
    ca marche tres bien ,malgrés le fait que je ne comprene pas ou est l erreur dans l unit que j utilisais avant . la seule diference est que la tienne utilise Wnetaddconnection3 et moi Wnetaddconnection2.
    mais bref , ca marche et c'est l essentiel

    merci !!

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

Discussions similaires

  1. Comment faire de l'XML avec Delphi 5 ?
    Par laclac dans le forum Débuter
    Réponses: 1
    Dernier message: 03/12/2007, 09h04
  2. Réponses: 1
    Dernier message: 23/03/2007, 17h09
  3. [Réseaux] Comment faire un sniffer en JAVA ?
    Par Alec6 dans le forum Entrée/Sortie
    Réponses: 17
    Dernier message: 09/12/2005, 03h24
  4. comment faire un net send avec winpcap?
    Par Zetmurin dans le forum Développement
    Réponses: 2
    Dernier message: 14/06/2005, 07h13
  5. Creer un partage réseaux, comment faire?
    Par Tartar Ukid dans le forum C++Builder
    Réponses: 5
    Dernier message: 21/01/2005, 15h11

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