Login+password pour lire un fichier sur le reseau

Résolu
frbos Messages postés 27 Date d'inscription vendredi 4 novembre 2011 Statut Membre Dernière intervention 4 novembre 2011 - 1 sept. 2006 à 17:15
cs_Delphiprog Messages postés 4297 Date d'inscription samedi 19 janvier 2002 Statut Membre Dernière intervention 9 janvier 2013 - 17 sept. 2006 à 14:34
Bonjour
J'ai besoins de lire en delphi un fichier log situé sur le reseau.
Y a-t-il un moyen de passer en parametre les login et password me permettant d'acceder a ce fichier ?
Merci

frb

13 réponses

cs_Delphiprog Messages postés 4297 Date d'inscription samedi 19 janvier 2002 Statut Membre Dernière intervention 9 janvier 2013 32
3 sept. 2006 à 21:16
Salut à tous,

Si c'est juste un problème de se connecter à un lecteur réseau, tu peux utiliser le composant TNetDrive très bien fait (source fournie). Personnellement, j'y ai apporté quelques modifications si cela peut t'aider, fait le moi savoir.
May Delphi be with you !


<hr color="#008000" />
Pensez à cliquer sur Réponse acceptée lorsque la réponse vous convient.
3
cs_Delphiprog Messages postés 4297 Date d'inscription samedi 19 janvier 2002 Statut Membre Dernière intervention 9 janvier 2013 32
17 sept. 2006 à 14:34
Tout est bien qui finit bien.
L'espace manquant provient de la mise en page de ce site (phénomène étrange avec les copier/coller en RTF).
J'ai oublié de mentionner qu'il fallait créer un package ou en utiliser un existant tellement c'était évident pour moi.
Enfin, désolé pour le retard dans la réponse mais je rentre d'une semaine de vacances .

Il en reste plus qu'à valider la réponse...

May Delphi be with you !
<hr color="#008000" />
Pensez à cliquer sur Réponse acceptée lorsque la réponse vous convient.
3
cptpingu Messages postés 3837 Date d'inscription dimanche 12 décembre 2004 Statut Modérateur Dernière intervention 28 mars 2023 123
1 sept. 2006 à 18:13
Oui, c'est possible. Une petite recherche sur google t'aurais donné ceci:

Si c'est un protection htaccess:
http://delphi.developpez.com/faq/?page=indy_idhttp#indyidhttphtaccess

Si c'est un login en php, tu remplis les informations de Post ou de Get:
Get:
http://delphi.developpez.com/faq/?page=indy_idhttp#indysimulerget
Post:
http://delphi.developpez.com/faq/?page=indy_idhttp#indyvaliderpost

Pour de plus amples détails:
www.google.com !
0
frbos Messages postés 27 Date d'inscription vendredi 4 novembre 2011 Statut Membre Dernière intervention 4 novembre 2011
1 sept. 2006 à 20:18
Le probleme n'est pas la... Le fichier que je veux lire est un fichier situé sur un serveur auquek j'ai acces avec un compte admin...
Je fais une appli en delphi qui doit analyser un fichier log sur un serveur de licences (flexlm). Pas de serveur WEB... Pas de htaccess, pas de GET ou POST...
J'ai bien sur chercher sur mon ami google...
Merci
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cptpingu Messages postés 3837 Date d'inscription dimanche 12 décembre 2004 Statut Modérateur Dernière intervention 28 mars 2023 123
1 sept. 2006 à 20:53
Dans ce cas au temps pour moi. Pourrais-t-on avoir le plus de détails possible ?
As-tu au moins un acces FTP ?
0
frbos Messages postés 27 Date d'inscription vendredi 4 novembre 2011 Statut Membre Dernière intervention 4 novembre 2011
2 sept. 2006 à 10:55
Je dois lire un fichier \\serveur\c$\program files\flexlm\licencing\fichier.log
J'ai un compte "admin" pour acceder a ce serveur. Mon compte "courant" n'y accede pas.
Mon appli ne peut donc pas le lire.
Je n'avais pas pense au FTP... Ca pourrait etre une solution ?

frb
0
elguevel Messages postés 718 Date d'inscription jeudi 19 décembre 2002 Statut Membre Dernière intervention 22 novembre 2016 3
3 sept. 2006 à 17:56
Et un lecteur réseau ?

Tu auras ainsi un chemin du genre Z:\flexlm\licencing\fichier.log

<!-- blocPrincipal -->
 /\_/\
( o.o ) ~ ElGuevel ~
 > ^ <
0
frbos Messages postés 27 Date d'inscription vendredi 4 novembre 2011 Statut Membre Dernière intervention 4 novembre 2011
3 sept. 2006 à 20:18
J'y ai pense. Monter et demonter le disque une fois le traitement fini. Mais justement, il me demande un login...
Je voudrai le passe en parametre

frb
0
frbos Messages postés 27 Date d'inscription vendredi 4 novembre 2011 Statut Membre Dernière intervention 4 novembre 2011
4 sept. 2006 à 15:04
MERCI Delphiprog...
J'ai l'impression que cela repond tout a fait a mon probleme. Je vais essayer ca rapidement !!!
Quelles ameliorations as-tu apporte a ce composant ?
Encore merci

frb
0
cs_Delphiprog Messages postés 4297 Date d'inscription samedi 19 janvier 2002 Statut Membre Dernière intervention 9 janvier 2013 32
6 sept. 2006 à 09:30
D'après la description de ton problème, ce composant semblait effectivement correspondre à tes besoins.
En fait d'améliorations, c'est plus à une restructuration que j'ai procédé (allègement du code lourd, maladroit ou redondant notamment au niveau des chaînes et suppression des ShowMessage bloquants).
En voici le résultat (aucune fonctionnalité ajoutée ou modifiée) :
(*

  This component was downloaded from the
  About Delphi Programming site

  @author(http://delphi.about.com)

  TNetDrive is a non-visual component that connects a network path to a drive name.

  Find more: http://delphi.about.com/library/weekly/aa061503a.htm
  @lastmod(DELPHIPROG, le 01/08/2006 17:15:57)
*)

unit NetDrive;

{$WARN UNIT_PLATFORM OFF}

interface

uses
  Windows, SysUtils, Classes, Controls, Forms, Dialogs;

type
  TNetDrive =   class (TComponent)
  private
    FErrorString: string;
    FDrive: string;
    FOnDisconnect: TNotifyEvent;
    FOnConnect: TNotifyEvent;
    procedure SetOnConnect(const Value: TNotifyEvent);
    procedure SetOnDisconnect(const Value: TNotifyEvent);
    function FreeDriveName: string;
    function DriveExists(const ADrive: string): boolean;
  protected
  public
    constructor Create(AOwner: TComponent); override;
    function Connect(const AResource, AUser, APassword: string): string;
    function Disconnect: boolean;
    property Drive: stringread FDrive;
    property ErrorString: stringread FErrorString;
  published
    property OnConnect: TNotifyEvent read FOnConnect write SetOnConnect;
    property OnDisconnect: TNotifyEvent read FOnDisconnect write
      SetOnDisconnect;
  end;

procedureRegister;

implementation

uses
  FileCtrl;

resourcestring
  rsERROR_ACCESS_DENIED  = 'Access to the network resource was denied.';
  rsERROR_ALREADY_ASSIGNED = 
    'The local device specified by lpLocalName is already connected to a network resource.';
  rsERROR_BAD_DEV_TYPE =
    'The type of local device and the type of network resource do not match.';
  rsERROR_BAD_DEVICE = 'The value specified by lpLocalName is invalid.';
  rsERROR_BAD_NET_NAME =
    'The value specified by lpRemoteName is not acceptable to any network resource provider. The resource name is invalid, or the named resource cannot be located.';
  rsERROR_BAD_PROFILE = 'The user profile is in an incorrect format.';
  rsERROR_BAD_PROVIDER =
    'The value specified by lpProvider does not match any provider.';
  rsERROR_BUSY =
    'The router or provider is busy, possibly initializing. The caller should retry.';
  rsERROR_CANCELLED =
    'The attempt to make the connection was cancelled by the user through a dialog box from one of the network resource providers, or by a called resource.';
  rsERROR_CANNOT_OPEN_PROFILE =
    'The system is unable to open the user profile to process persistent connections.';
  rsERROR_DEVICE_ALREADY_REMEMBERED =
    'An entry for the device specified in lpLocalName is already in the user profile.';
  rsERROR_EXTENDED_ERROR =
    'A network-specific error occured. Call the WNetGetLastError function to get a description of the error.';
  rsERROR_INVALID_PASSWORD = 'The specified password is invalid.';
  rsERROR_NO_NET_OR_BAD_PATH =
    'A network component has not started, or the specified name could not be handled.';
  rsERROR_NO_NETWORK = 'There is no network present.';
  rsERROR_UNKNOWN_ERROR =
    'An unknown error has occured attempting to connect to %s.';
  rsERROR_DEVICE_IN_USE =
    'The device is in use by an active process and cannot be disconnected.';
  rsERROR_NOT_CONNECTED =
    'The name specified by the lpName parameter is not a redirected device, or the system is not currently connected to the device specified by the parameter.';
  rsERROR_OPEN_FILES =
    'There are open files, and the fForce parameter is FALSE.';

 procedure Register;
begin
  RegisterComponents('delphi.about.com', [TNetDrive]);
end;

{ TNetDrive }

function TNetDrive.Connect(const AResource, AUser, APassword: string): string;
var
  n: NETRESOURCE;
  i: integer;
begin
  FErrorString : = EmptyStr;
  FDrive :=  '';
  n.dwScope := RESOURCE_GLOBALNET;
  n.dwType := RESOURCETYPE_DISK;
  n.dwDisplayType := RESOURCEDISPLAYTYPE_GENERIC;
  n.dwUsage := RESOURCEUSAGE_CONNECTABLE;
  n.lpLocalName := PChar(FreeDriveName);
  n.lpRemoteName := PChar(AResource);
  n.lpComment := '';
  n.lpProvider := '';
  i := WNetAddConnection2(n, PChar(APassword), PChar(AUser), 0);
   case  i of
    NO_ERROR:
      begin
        Sleep(500);
        FDrive : = n.lpLocalName;
        repeatuntil DriveExists(FDrive);

        if Assigned(FOnConnect) then
          FOnConnect(self);
      end;

    ERROR_ACCESS_DENIED: FErrorString :=  rsERROR_ACCESS_DENIED;
    ERROR_ALREADY_ASSIGNED: FErrorString := rsERROR_ALREADY_ASSIGNED;
    ERROR_BAD_DEV_TYPE:FErrorString := rsERROR_BAD_DEV_TYPE;
    ERROR_BAD_DEVICE:FErrorString := rsERROR_BAD_DEVICE;
    ERROR_BAD_NET_NAME:FErrorString := rsERROR_BAD_NET_NAME;
    ERROR_BAD_PROFILE:FErrorString := rsERROR_BAD_PROFILE;
    ERROR_BAD_PROVIDER:FErrorString := rsERROR_BAD_PROVIDER;
    ERROR_BUSY: FErrorString := rsERROR_BUSY;
    ERROR_CANCELLED: FErrorString := rsERROR_CANCELLED;
    ERROR_CANNOT_OPEN_PROFILE:FErrorString := rsERROR_CANNOT_OPEN_PROFILE;
    ERROR_DEVICE_ALREADY_REMEMBERED:FErrorString := rsERROR_DEVICE_ALREADY_REMEMBERED;
    ERROR_EXTENDED_ERROR: FErrorString := rsERROR_EXTENDED_ERROR;
    ERROR_INVALID_PASSWORD:FErrorString := rsERROR_INVALID_PASSWORD;
    ERROR_NO_NET_OR_BAD_PATH:FErrorString := rsERROR_NO_NET_OR_BAD_PATH;
    ERROR_NO_NETWORK: FErrorString := rsERROR_NO_NETWORK;
  else
    FErrorString := Format(rsERROR_UNKNOWN_ERROR, [AResource]);
   end ;
  Result : = FDrive;
end;

constructor TNetDrive.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
//   FErrorString :=  '';
//   FDrive := '';
  FOnDisconnect :=  nil ;
  FOnConnect : = nil;
end;

function TNetDrive.Disconnect: boolean;
begin
  result :=  false;
  FErrorString := EmptyStr;
   if  FDrive <> ''then
  begin
    case WNetCancelConnection2(PChar(FDrive), 0, true) of
      NO_ERROR:
        begin
          FDrive : = '';
          Result :=  true;
           if  Assigned(FOnDisconnect) then
            FOnDisconnect(self);
        end;
      ERROR_BAD_PROFILE: FErrorString : = rsERROR_BAD_PROFILE;
      ERROR_CANNOT_OPEN_PROFILE: FErrorString :=  rsERROR_CANNOT_OPEN_PROFILE;
      ERROR_DEVICE_IN_USE: FErrorString := rsERROR_DEVICE_IN_USE;
      ERROR_EXTENDED_ERROR: FErrorString := rsERROR_EXTENDED_ERROR;
      ERROR_NOT_CONNECTED: FErrorString := rsERROR_NOT_CONNECTED;
      ERROR_OPEN_FILES: FErrorString := rsERROR_OPEN_FILES;
     end ;
  end;
end;

function TNetDrive.DriveExists(const ADrive: string): boolean;
var
  buf: string;
begin
  GetDir(0, buf);
{$I-}
  ChDir(ADrive);
{$I+}  Result : (IOResult  0);
  ChDir(buf);
 end ;

function TNetDrive.FreeDriveName: string;
var
  l: TStringList;
  d: TDriveComboBox;
  t: char;
  i: integer;
begin
  l : = TStringList.Create;
  d :=  TDriveComboBox.Create(Application.MainForm);
  d.Parent := Application.MainForm;
  d.Visible := false;
  l.Assign(d.Items);
  d.Free;
   for  i : = 0 to l.Count - 1 do
    l[i] :=  copy(l[i], 1, 1);
  t := 'd';
  result := '';   while  (t < 'z') <gras>and (result</gras>  '') do
     if  l.IndexOf(t)  = -1then
      result :=  t
    else
      inc(t);
  l.Free;
   if  result <> ''then
    result : = result + ':';
end;

procedure TNetDrive.SetOnConnect(const Value: TNotifyEvent);
begin
  FOnConnect :=  Value;
 end ;

procedure TNetDrive.SetOnDisconnect(const Value: TNotifyEvent);
begin
  FOnDisconnect : = Value;
end;

end.

En espérant que cela t'aidera.

May Delphi be with you !
<hr color="#008000" />
Pensez à cliquer sur Réponse acceptée lorsque la réponse vous convient.
0
frbos Messages postés 27 Date d'inscription vendredi 4 novembre 2011 Statut Membre Dernière intervention 4 novembre 2011
12 sept. 2006 à 11:20
Bonjour DelphiProg

J'essaie d'utiliser TNetDrive, et j'ai deux soucis...
1 - Sur ton source, ligne 39 property Drive: stringread FDrive; stringread n'est pas reconnu
2- Je n'arrive pas a installer le composant. J'utilise delphi 2006. Est-ce qu'il suffut de faire un uses de l'unit dans mon appli ?
Merci
frb
0
frbos Messages postés 27 Date d'inscription vendredi 4 novembre 2011 Statut Membre Dernière intervention 4 novembre 2011
12 sept. 2006 à 11:25
DelphiProg
Oublie le point 1 de mon dernier post... Il manque simplement l'espace entre string et read...
Désolé.

frb
0
frbos Messages postés 27 Date d'inscription vendredi 4 novembre 2011 Statut Membre Dernière intervention 4 novembre 2011
12 sept. 2006 à 13:33
DelphiProg
Ce coup ci, c'est bon. J'ai reussi a installer le composant. Je ne savais pas qu'il fallait passer par un package...
Encore merci, le composant convient tout a fait...

frb
0
Rejoignez-nous