I'd like to know with a .net language(C# or VB) if I can detect when a new app is launched. e.g: an user opens Firefox.exe from desktop (not from my app!), is it possible to detect this event from my app? Also is it possible to "pause" it before running it? So for example when an user double-clicks an application, my app comes first and then it displays a message if he is sure to open that file with Yes and No buttons. I don't need all code, I just need to know how to catch that event that can happen anywhere in system.
Asked
Active
Viewed 421 times
-1
-
I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Nov 02 '14 at 20:05
-
You may try to catch it with system level hook for some system library, so when a new application is started, it will load hooked library and you can notify your application about it. But it might be not easy to do. – Sergey Litvinov Nov 02 '14 at 20:07
-
You could try to start a low- priority backgound thread that periodically calls 'Process.GetProcesses()' and compare the list with an earlier call. But to pause the execution, I don't think that that is possible. – Sjips Nov 02 '14 at 20:12
-
1possible duplicate of [Detect when exe is started vb.net](http://stackoverflow.com/questions/18757391/detect-when-exe-is-started-vb-net) – Ňɏssa Pøngjǣrdenlarp Nov 02 '14 at 20:17
-
possible duplicate of [How to detect a process start & end using c# in windows?](http://stackoverflow.com/questions/8455873/how-to-detect-a-process-start-end-using-c-sharp-in-windows) – B.K. Nov 02 '14 at 20:22
-
@Plutonix and B.K. it is not a duplicate as I saw them already and it is monitoring a custom process. I want to detect new processes which is different. – xpirt Nov 02 '14 at 20:46
-
just leave out the `AND` clause in the query...[see also](http://stackoverflow.com/a/26234529/1070452) – Ňɏssa Pøngjǣrdenlarp Nov 02 '14 at 20:51
-
Maybe helpful: http://stackoverflow.com/q/25008706/103167 – Ben Voigt Nov 03 '14 at 04:17
1 Answers
0
There are some Windows API functions in user32.dll that you can use in your .NET application through System.Runtime.InteropServices.DllImport to get the information you're looking for. Take a look at GetWindowThreadProcessId. For sample code, see http://www.c-sharpcorner.com/UploadFile/satisharveti/ActiveApplicationWatcher01252007024921AM/ActiveApplicationWatcher.aspx. Because applications tend to become active when they are launched, you'll find that the techniques used in that example will cause it to detect new app launches.
That doesn't answer the question about letting the user confirm whether they want to run an app, but it will get you part of the way towards what you are trying to do.

RedGreenCode
- 2,195
- 1
- 25
- 33