I am writing a program that must register time of starting a process such as notepad.
I thought that it is good to create a Timer that checks all of processes every second. But I think that it will slow down the user’s computer. Is there a better way of doing this?
I am writing a program that must register time of starting a process such
Share
Initially determine for all running processes the creation time. Then
use WMI to register for process creation events.
See the code below for a small example on how to use WMI for process creation events:
BEGIN EDIT:
I’ve further investigated process creation detection with WMI and there is a (more) resouces friendly solution (but needs administrative privileges) using the
Win32_ProcessStartTraceclass (please see TECHNET for further information):In this solution you do not have to set an polling interval.
END EDIT
BEGIN EDIT 2:
You could use the
Win32_ProcessStopTraceclass to monitor process stop events. To combine both process start and process stop events use theWin32_ProcessTraceclass. In the event handler use theClassPathproberty to distinguish between start/stop events:END EDIT 2