Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
We have a requirement as below.


At the end of every day, the .NET application should calculate for how much time the Outlook was open on the computer.



Please help me how can I do this task.
Posted

You can build a windows service, that periodical checks if process "outlook.exe" is running, if it is then your service starts tracking usage time.
 
Share this answer
 
In addition to what LNogueira already said, you can use the WaitForSingleObject Function (Windows)[^] from the Win32 API (you can use it directly from C++ or by marshalling from C# and VB).

If you pass the process handle of outlook.exe to this function, with the second parameter equal to INFINITE (INFINITE is defined in WinBase.h as 0xFFFFFFFF), the function does not return until the specified process terminates (it doesn't matter how it terminates).

Then you can work this way:


  1. Test if the process outlook.exe is running
  2. If outlook.exe is not running wait for a while then return to the step (1); otherwise go on with the step (3)
  3. Save the current time (this is the time when outlook is started)
  4. Get the handle of the outlook.exe process
  5. Call WaitForSingleObject to wait until the outlook.exe process terminates
  6. Get the current time and update your statistics
  7. Return to the step (1)
 
Share this answer
 
Comments
Shining Legend 13-Jul-10 4:25am    
Reason for my vote of 2
Explained step by step what to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900