Store events from other programs

I want to store events from other applications in my own app. Examples of events: when Word is opened, minimized or a file is opened.

Is such a thing possible?


Use EventLog.

You must set EnableRaisingEvents property to true

And When an event add to specified event log the EntryWritten event handler will raise

It is the simplest way to handle os events

sample code

private void frmMain_Load(object sender, EventArgs e) { System.Diagnostics.EventLog s = new System.Diagnostics.EventLog("Application", ".", ""); s.EnableRaisingEvents = true; s.EntryWritten += delegate(object st, System.Diagnostics.EntryWrittenEventArgs ew) { MessageBox.Show(ew.Entry.Message); }; }


Running a program and opening a file are OS events (they involve security checks), and can be captured using the Windows built-in auditing features. Those are off-topic here, direct further questions to

Minimizing a program is an example of an application message, to get those you would need to install a hook using SetWindowsHookEx. Beginning in .NET 4 (which introduces parallel runtime support), this can be done with C#, but it's not recommended. One huge issue you need to be aware of is that your event capture code must NEVER generate events of its own, or else you will start a chain reaction that crashes all running programs.

人吐槽 人点赞



用户名: 密码:
验证码: 匿名发表


查看评论:Store events from other programs