C# - which programs have been opened since the user opened my program
I need to know which programs hav开发者_开发问答e been opened since the user opened my program - a program activity monitor..
How can i do that?
You can use WMI to get notified when a new process is started: Using WMI to monitor process creation, deletion and modification in .NET
Use Process.GetProcesses
to list the processes at startup, keep calling and comparing the results.
New processes should correspond to opened programs.
Take a look at the answer by @Giorgi that utilized WMI and offers event registration for process startup as well. Looks like a very nice way to do this.
You can call Process.GetProcesses
at launch, then call it again later and see what changed.
If you want to be notified when a program launches, you'll need to use WMI.
Hi You could in fact act in this way:
as soon as your program starts you enumerate all current processes ( depends on you if you want to monitor everything including windows services or only UI applications in which case Win32 API EnumWindows is your friend ).
then every few seconds or minutes you can do the same and compare what is opened now and was not opened before, that's your list.
easy and quick solution, otherwise you could implement something more complicated like sys internals Process Explorer or list processes.
精彩评论