Autor Beitrag
theend
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mi 09.03.05 09:43 
hi,
ich habe ein Programm (teilweise selber, teilweise aus dem Net oder Foren Programmiert) mit dem ich prüfe ob ein Programm XXX.exe und mehrere Netzwerkserver (die in der Datei XXX.txt mit IP-Adresse eingetragen sind) Online sind, allerdings tretten immer wieder Fehler auf, die da währen:

Das Programm sendet eine Offline meldung obwohl das Programm bzw. der Netzwerk Rechner Online ist.

Kann mir da wer helfen?

ausblenden volle Höhe Delphi-Quelltext
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:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
unit tasks1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, tlhelp32, StdCtrls, ExtCtrls, ShellAPI, IdBaseComponent,
  IdComponent, IdRawBase, IdRawClient, IdIcmpClient;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    ListBox1: TListBox;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Timer2: TTimer;
    ICMP: TIdIcmpClient;
    Timer3: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Timer3Timer(Sender: TObject);
    procedure ICMPReply(ASender: TComponent;
      const AReplyStatus: TReplyStatus);
  private
    { Private-Deklarationen }
  public
    { Private-Deklarationen }
  end;

var
  Form1: TForm1;
  xx: Boolean;

implementation

{$R *.dfm}

{******************************************************************************}
{**                                                                          **}
{** Prozesse in Stringliste schreiben                                        **}
{**                                                                          **}
{******************************************************************************}
procedure GetProcessList(sl: TStrings);
var
  hProcSnap: THandle;
  pe32: TProcessEntry32;
begin
  { Snapshot machen *PENG* }
  hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
  if hProcSnap = INVALID_HANDLE_VALUE then exit;

  pe32.dwSize := SizeOf(ProcessEntry32);

  { wenn es geklappt hat }
  if Process32First(hProcSnap, pe32) = true then
    { und los geht's }
    { Process32First liefert auch schon einen Prozess, den System-Prozess }
    sl.Add(pe32.szExeFile);
    while Process32Next(hProcSnap, pe32) = true do
    begin
      sl.Add(pe32.szExeFile);
      if AnsiCompareStr(LowerCase(pe32.SZExeFile),LowerCase('XXX.exe')) = 0 then
      begin
        xx := true;
      end
      else
      begin
         xx := false;
      end
    end;
  CloseHandle(hProcSnap);
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Clear;
GetProcessList(ListBox1.Items);
if xx = true then
begin
Timer1.Enabled := true;
end
else
begin
Timer2.Enabled := true;
end
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
ListBox1.Clear;
GetProcessList(ListBox1.Items);
if not xx = true then
begin
Timer1.Enabled := false;
ShellExecute(Application.Handle, 'open', 'mail.bat', nil, nil, SW_SHOW);
Timer2.Enabled := true;
end;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
ListBox1.Clear;
GetProcessList(ListBox1.Items);
if xx = true then
begin
Timer2.Enabled := false;
Timer1.Enabled := true;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Timer2.Enabled := false;
Timer1.Enabled := false;
ListBox1.Clear;
GetProcessList(ListBox1.Items);
if xx = true then
begin
Timer1.Enabled := true;
end
else
begin
Timer2.Enabled := true;
end
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Timer2.Enabled := false;
Timer1.Enabled := false;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
ShellExecute(Application.Handle, 'open', 'C:\XXX.exe', nil, nil, SW_SHOW);
end;

procedure TForm1.Timer3Timer(Sender: TObject);
  i: integer;
  Dateiname: TStringList;
begin
if FileExists('XXX.txt') then
  begin

  ICMP.OnReply := ICMPReply;
  i := 0;
  Dateiname := TStringList.Create;
  Dateiname.LoadFromFile('XXX.txt');
  
    while i <= Dateiname.Count - 1 do
    begin
     ICMP.Host := Dateiname.Strings[i];
     ICMP.Ping;
     Application.ProcessMessages;
     i:= i + 1;
    end
  end
end;

procedure TForm1.ICMPReply(ASender: TComponent;
  const AReplyStatus: TReplyStatus);
begin
if AReplyStatus.TimeToLive = 0 then ShellExecute(Application.Handle, 'open', 'mailto.exe', nil, nil, SW_SHOW);
end;

end.

Timer zeiten:
timer1: 15 sec
timer2: 5 sec
timer3: 30 sec
theend Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Do 10.03.05 10:06 
hm... kann mir da keiner helfen?

im bezug auf die Netzwerkserver hab ich das Problem das ich einen Ping sende und immer nur eine antwort bekomme, und wen diese aus welchen Gründen auch immer ein Request Time Out ist - weil das netzwerk grade ausgelatet ist oder so - löst er gleicht meine Fehlerbenachrichtigung aus.
Wie kann ich sagen wir 4 Ping Antworten haben und schaun eine davon durchkommt und erst wenn alle 4 Time Out haben in meine Fehlerbenachrichtigung wechseln

ausblenden volle Höhe Delphi-Quelltext
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:
procedure TForm1.Timer3Timer(Sender: TObject);
var  i: integer;
  Dateiname: TStringList;
begin
if FileExists('XXX.txt') then
  begin

  ICMP.OnReply := ICMPReply;
  i := 0;
  Dateiname := TStringList.Create;
  Dateiname.LoadFromFile('XXX.txt');
 
    while i <= Dateiname.Count - 1 do
    begin
     ICMP.Host := Dateiname.Strings[i];
     ICMP.Ping;
     Application.ProcessMessages;
     i:= i + 1;
    end
  end
end;

procedure TForm1.ICMPReply(ASender: TComponent;
  const AReplyStatus: TReplyStatus);
var cam: string;
datum: string;
zeit: string;
begin
cam := Dateiname.Strings[i];
datum := DateToStr(Date);
zeit := TimeToStr(now);
if AReplyStatus.TimeToLive = 0 then ShellExecute(Handle, PChar('open'), PChar('mailto.exe'), nil, nil, SW_SHOW);
end;