Click here to Skip to main content
16,018,006 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Helllllooo....
I am working on a project where I've to maintain the logs of a system.
I want to store whenever user open an application.
I dont know how to do that...
I just want to create a event whenever user runs an application...
thanks
help please..
Posted

This is pretty easy enough. You might need to use WMI. I am giving you an example.

C#
public partial class Form1 : Form
    {
        public System.Management.ManagementEventWatcher mgmtWtch;

        public Form1()
        {
            InitializeComponent();
            mgmtWtch = new System.Management.ManagementEventWatcher("Select * From Win32_ProcessStartTrace");
            mgmtWtch.EventArrived += new System.Management.EventArrivedEventHandler(mgmtWtch_EventArrived);
            mgmtWtch.Start();
        }

        private void mgmtWtch_EventArrived(object sender, System.Management.EventArrivedEventArgs e)
        {
            MessageBox.Show((string)e.NewEvent["ProcessName"]);
        }       
    }



Run this program and keep it running. Then Open your notepad you will see that the messagebox will pop up and give you the process name that you right now run in.
 
Share this answer
 
Comments
fjdiewornncalwe 23-Aug-11 8:21am    
+5. Very nice and simple.
XeeShaN AbbAs 23-Aug-11 10:27am    
thanks man...
this show the process name is there any function which could show the application name..??
Sergey Alexandrovich Kryukov 23-Aug-11 23:25pm    
Good solution, my 5.
--SA
http://support.microsoft.com/kb/307024[^]


do it in the Main() method of your application.

mark as answer if solved you problem..
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900