C#中的应用程序列表 [英] Applications list in c#

查看:62
本文介绍了C#中的应用程序列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Helllllooo ....
我正在一个项目中,我必须维护系统的日志.
我想在用户打开应用程序时进行存储.
我不知道该怎么办...
我只想在用户运行应用程序时创建一个事件...
谢谢
请帮助..

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

推荐答案

这很容易.您可能需要使用WMI.我给你举个例子.

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

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.


^ ]


在应用程序的Main()方法中进行操作.

如果解决了您的问题,请标记为答案.
http://support.microsoft.com/kb/307024[^]


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

mark as answer if solved you problem..


这篇关于C#中的应用程序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆