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

Delphi Discussion :

Creer service avec Delphi7


Sujet :

Delphi

  1. #1
    Membre éclairé Avatar de Soulama
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2004
    Messages
    619
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2004
    Messages : 619
    Par défaut Creer service avec Delphi7
    Salut tout le monde,
    voila mon probleme jai creé un service avec Delphi7(voir Code), puis je lai installer avec la commande: c:\service\ping.exe -install, ca a bien marcher linstallation, le probleme c qu'il ne ce passe rien du tout, le progi doi faire juste un ping a google toutes les 30 secondes et ecrire le resultat ds un fichier log, jai aucune ideé pourquoi ca ne marche pas??
    tout ideé est la bien venue,
    merci
    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
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
     
    unit PingCheck;
     
    interface
     
    uses
      Windows, Messages, SysUtils,
      Classes, Graphics, Controls,
      SvcMgr, Dialogs, IdIcmpClient,
      ExtCtrls, iniFiles;
     
    type
      TServicePingCheck = class(TService)
        procedure ServiceStart(Sender: TService; var Started: Boolean);
      private
        { Private-Deklarationen }
      public
        function GetServiceController: TServiceController; override;
        procedure TimerEvent(Sender: TObject);
        { Public-Deklarationen }
      end;
     
    var
      ServicePingCheck: TServicePingCheck;
     
    implementation
     
    {$R *.DFM}
     
    procedure ServiceController(CtrlCode: DWord); stdcall;
    begin
      ServicePingCheck.Controller(CtrlCode);
    end;
     
    function TServicePingCheck.GetServiceController: TServiceController;
    begin
      Result := ServiceController;
    end;
     
    Function GetInterVal: Integer ;
    Var
      Ini: TIniFile ;
      StrFile: String;
    Begin
      StrFile:= ExtractFileName(ParamStr(0))+'Config.ini';
      Ini:= TIniFile.Create(StrFile) ;
      Try
        Result:= Ini.ReadInteger('Timer', 'interval', 30)*1000;
      Finally
        FreeAndNil(Ini);
      End ;
    End ;
     
    {*******************************************************************************
      Ping a Sever
    *******************************************************************************}
    Function MyPing2(StrServer: String): Boolean ;
    var
      i : Integer;
      icmp : TidIcmpClient ;
      S: String;
    begin
      Result :=False;
      icmp := TidIcmpClient.Create(nil) ;
      try
        try
          ICMP.Host := StrServer;
          ICMP.Ping;
          S:= icmp.ReplyData ;
          if s<>'' Then
            Result:= True ;
        except
       end;
      finally
        FreeAndNil(icmp);
      end ;
    end ;
     
    Function GetPingDestination: String;
    Var
      Ini: TIniFile ;
      StrFile: String;
    Begin
      StrFile:= ExtractFileName(ParamStr(0))+'Config.ini';
      Ini:= TIniFile.Create(StrFile) ;
      Try
        Result:= Ini.ReadString('Server', 'IPAddress', 'www.google.de');
      Finally
        FreeAndNil(Ini);
      End ;
    End ;
     
    {*******************************************************************************
      Log File
    *******************************************************************************}
    procedure Log(Action, comment: String);
    var
      LogText, Str : String   ;
      LogFile : TextFile ;
    begin
      LogText := DateTimeToStr(NOW)+#9+Action+':'+#9+comment ;
      Str:= 'c:\programme\service\Log.txt';
      AssignFile (LogFile, Str);
      {$I-}
      if FileExists(Str) Then
        Append (LogFile)
      Else
        Rewrite(LogFile);
      Try
        WriteLn (LogFile, LogText);
      Finally
        CloseFile (LogFile);
      End ;
      {$I+}
    end;
     
    {*******************************************************************************
      Timer Event
    *******************************************************************************}
    procedure TServicePingCheck.TimerEvent(Sender: TObject);
    const
    {$J+}
       counter : Integer = 0; 
    {$J-}
    Var
      ip: String;
    begin
      inc(counter);
      IP:= GetPingDestination;
      Try
        MyPing2(Ip);
        Log('Ping Okay','Destination IP: '+IP+', Counter: '+inttostr(counter));
      Except on E:Exception do
        Log('ERROR Ping','Destination IP: '+IP+', Counter: '+inttostr(counter)+', '+e.Message);
      End ;
    end;
     
    procedure TServicePingCheck.ServiceStart(Sender: TService; var Started: Boolean);
    Var
      Timer: TTimer;
    begin
      Timer:= TTimer.Create(Self);
      Timer.Enabled:= False;
      Timer.Interval:= GetInterVal ;
      Timer.OnTimer:= TimerEvent ;
      Timer.Enabled:= True ;
      Started:= True ;
    end;
     
    end.

  2. #2
    Membre Expert

    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    685
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 685
    Par défaut
    A mon goût, il en manque un peu pour que ca fonctionne :

    procedure TServicePingCheck.ServiceExecute(Sender: TService);
    begin
    while not Terminated do
    ServiceThread.ProcessRequests(True);
    end;
    Testes de rajouter ce bout de code et dis nous si ca marche...

  3. #3
    Membre éclairé Avatar de Soulama
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2004
    Messages
    619
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2004
    Messages : 619
    Par défaut
    Bravo Reisubar, ca fonctione maintenat.
    bocoup

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

Discussions similaires

  1. Déploiement de Web Service avec InstallShield
    Par _beber85 dans le forum Services Web
    Réponses: 7
    Dernier message: 12/07/2006, 13h28
  2. comment on peut faire un service avec builder c++
    Par infoactif dans le forum C++Builder
    Réponses: 8
    Dernier message: 11/08/2005, 17h33
  3. Creer onglet avec forms9
    Par simpletz dans le forum Forms
    Réponses: 5
    Dernier message: 10/08/2005, 12h46
  4. creer champ avec valeur constante dans resultat de requete
    Par freejeje dans le forum PostgreSQL
    Réponses: 1
    Dernier message: 20/05/2005, 10h52
  5. Réponses: 3
    Dernier message: 21/09/2003, 15h52

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