Start time of program

user_
user_ used Ask the Experts™
on
I have tow program P1 and P2 then I start P1 after 1 minutes start P2, now how can I know which one is latest one running, how can know the start time of each process currently running?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
There are propably many ways to do this, but here's a few tips:

-Check time for both applications when they start (formCreate or else).
-Store time, for example in a file that other application has access, if needed.
-When prog starts, and it finds a time-file, it compares 2 prog times. If no file found, write a new time-file.
Commented:
To get create time for current process:

function GetProcessCreateTime : TDateTime;
Var
  CreateTime, ExitTime, KernelTime, UserTime :  TFileTime;
  SysTime : TSystemTime;
Begin
  Result := 0;
  If GetProcessTimes(GetCurrentProcess, CreateTime, ExitTime, KernelTime, UserTime) Then Begin
    FileTimeToSystemTime(CreateTime, SysTime);
    With SysTime Do
      Result := EncodeDate(wYear, wMonth, wDay) +  EncodeTime(wHour, wMinute, wSecond, wMilliseconds);
  End;
End;


Now, to check if your second application already started you can use FindWindow to get the application main window handle. This handle can be used also for communication between two processes (it should be faster then files).

Author

Commented:
to User137 : P1 and P2 ara not delphi program
let P1: calc.exe
    P2: notpad.exe

to Slavak : your function donot work i think it return false, i use D5 on w98
thanks for your repy.

OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Commented:
Sorry, I tested it on Win2k platform. May be on win9x system GetProcessTimes not implemented.

Now, can you explain what you try to do? I f your P1 & P2 programs "are not Delphi application" than you cannot enter my code into anyway :).

Author

Commented:
ok ,i will change "GetCurrentProcess" varible to the handel of what process i want to check ,am i right?
i will explain what i want :
i get some virus in EXE file ,when start to run that program  it show no window ,it is hidden, now by checking alt+ctrl+del list i have about 15 program running ,one of them is the EXE virus, now by checking start time of each pogram i detect the last one which is the virus,is my idea true?
thanks

Author

Commented:
ok ,i will change "GetCurrentProcess" varible to the handel of what process i want to check ,am i right?
i will explain what i want :
i get some virus in EXE file ,when start to run that program  it show no window ,it is hidden, now by checking alt+ctrl+del list i have about 15 program running ,one of them is the EXE virus, now by checking start time of each pogram i detect the last one which is the virus,is my idea true?
thanks

Commented:
I'm not sure that you can decide that last started program is a virus. Why you not using some antivirus programs?

Commented:
Sorry, sure you can decide it :), i'm not sure that it right

Author

Commented:
>Why you not using some antivirus programs?
there no prefect antivirus programs and some new virus are not listed in virus definition, and i want quick method to isolate the suspected program.

Regards

Commented:
you can try identify your processes. To make the list shorter stop unused services.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial