function TForm1.Checklogin() : Boolean;
var
FSnapshotHandle:THandle; //进程快照句柄
FProcessEntry32:TProcessEntry32; //进程入口的结构体信息
ContinueLoop, a:BOOL;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);//CreateToolhelp32Snapshot函数得到进程快照
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);//初始化
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);//Process32First 得到一个系统快照里第一个进程的信息
//进程ID
a := False;
while ContinueLoop do
begin
if loginProcessInfo.dwProcessId = FProcessEntry32.th32ProcessID then
begin
a := True;
Break;
end
else
begin
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
end;
if a then
begin
Result := True;
end
else
begin
Result := False;
end;
var
FSnapshotHandle:THandle; //进程快照句柄
FProcessEntry32:TProcessEntry32; //进程入口的结构体信息
ContinueLoop, a:BOOL;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);//CreateToolhelp32Snapshot函数得到进程快照
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);//初始化
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);//Process32First 得到一个系统快照里第一个进程的信息
//进程ID
a := False;
while ContinueLoop do
begin
if loginProcessInfo.dwProcessId = FProcessEntry32.th32ProcessID then
begin
a := True;
Break;
end
else
begin
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
end;
if a then
begin
Result := True;
end
else
begin
Result := False;
end;
end;
procedure TForm1.tmr1Timer(Sender: TObject);
begin
if checklogin() then
begin
end
else
begin
StartLogin();
Memo1.Lines.Add('[' + FormatdateTime('hh:nn:ss', Now)+ '] 登录服务已重启');
end;
end;