Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read the message

Status
Not open for further replies.

devilkind

Programmer
Joined
Dec 9, 2006
Messages
3
Location
RO
Well it's a bit complicated to explain but here it goes: I want to start a process and i need a way to find out the time while that process was running. HELP!
 
It's a bit complicated to help you if you are not able to explain.

That's easy to start a process, but it's mot that easy to find out the time it's been running.
You have to log the time when the process was started. I don't think "Windows" know it.

[tt]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do not underestimate the power of [!]Google[/!][/tt]
 
Code:
queryperformancefrequency(counts);
FillChar(StartInfo,SizeOf(TStartupInfo),#0);
  FillChar(ProcInfo,SizeOf(TProcessInformation),#0);
  StartInfo.cb := SizeOf(TStartupInfo);
  StartInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartInfo.wShowWindow := SW_HIDE;

  CreateProcess(PChar(edit1.text),nil, nil, nil,False,
            CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS,
            nil, nil, StartInfo, ProcInfo);
  QueryPerformanceCounter(Time);
  Ret := WaitForSingleObject(ProcInfo.hProcess, StrToInt(edit2.text));
  QueryPerformanceCounter(Aux);
  Time := Aux - Time;
  S1 := Format('%f', [Time/Counts]);
  if Ret = WAIT_TIMEOUT then
      TerminateProcess(ProcInfo.hProcess, 0);
I made it, this code above is the one i used. Time returns the number of seconds/100 that the process needed to run, but i wanted to stop the process after some time (time limit) and that's exactly what this code does.

edit1.text - process name
edit2.text - time limit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top