procedure CheckParentProc; var Pn: TProcesseNtry32; sHandle: THandle; ParentProc: HWND; Found: Boolean; begin ParentProc := 0;
sHandle := CreateToolHelp32SnapShot(TH32CS_SNAPALL, 0); try Found := Process32First(sHandle, Pn); //Search process while Found do //Loop all processes begin if CompareText(ExtractFileName(Pn.szExeFile), ExtractFileName(ParamStr(0))) = 0 then //It's me begin ParentProc := Pn.th32ParentProcessID; //Get parent process ID Break; end;
Found := Process32Next(sHandle, Pn); //Find next end;
if ParentProc > 0 then //Valid begin Found := Process32First(sHandle, Pn); while Found do begin if Pn.th32ProcessID = ParentProc then //It's my parent process begin ParentProc := Pn.th32ParentProcessID; //Get its parent process, my grandfather process :) Break; end;
Found := Process32Next(sHandle, Pn); //Find next end;
if ParentProc > 0 then begin Found := Process32First(sHandle, Pn); while Found do begin if Pn.th32ProcessID = ParentProc then begin if CompareText(UpperCase(ExtractFileName(Pn.szExeFile)), 'EXPLORER.EXE') = 0 then //Grandfather process is Explorer.exe begin ShowMessage('Debugger detected! Doggone it all!'); Break; end; end;
Found := Process32Next(sHandle, Pn); //Find next end; end; end; finally CloseHandle(sHandle); end; end;