Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to write code in C#,

In a Windows Service, How to continuously keep checking if outlook process has been opened or not. If outlook is opened it has to write the open time of outlook in a file. If outlook is closed it has to again write the close time of outlook in a file.
Posted

The Process.GetProcessesByName[^] method can test for a running instance of Outlook for you. If it's running then you can take the Process object that's returned and subscribe to the Exited[^] event. From here, you can look at the Process object again and use the StartTime[^] and ExitTime[^] properties to calculate whatever you want about it's run time and then save that to file.

The easiest way to do periodic File IO is with the static methods of the File[^] class.

Abhinav gave you a good link about how to make your service wake up and do something periodically.
 
Share this answer
 
YEs I have gone through the link content posted in previous answer and I can track the time when the process exits. But i need to build windows service in such a way that it should automatically detect if the outlook is opened and save that time in notepad.
 
Share this answer
 
Comments
Jimmanuel 23-Jul-10 8:39am    
OK, you made it sound like you already knew how to write a service. If not, see here: http://msdn.microsoft.com/en-us/library/aa984464%28v=VS.71%29.aspx

With that, you have the help to write a service, you have guidance on how to make it periodically do something, on how to check for Outlook, on how to know when it exits, on how to know it's run time and on how to write data to file. I'll leave it up to you to put all of the pieces together in the correct order.
See here[^].
 
Share this answer
 
Comments
Shining Legend 23-Jul-10 4:16am    
Reason for my vote of 1
somewhat helpful.

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