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?

Answer1:

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); }; }

Answer2:

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 ServerFault.com

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.

人吐槽 人点赞

Recommend

Comment

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

你可以使用这些语言

查看评论:Store events from other programs