zoukankan      html  css  js  c++  java
  • C# 查询所有设备的插拔事件

         private void test()

            {

                //Win32_DeviceChangeEvent  Win32_VolumeChangeEvent

                ManagementEventWatcher watcher = new ManagementEventWatcher();

                WqlEventQuery query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent  WHERE EventType = 2 or EventType = 3");

                watcher.EventArrived += (s, e) =>

                {

                    var txt = "";

                   foreach( var p in e.NewEvent.Properties)

                    {

                        txt += "name " + p.Name + " val " + p.Value + " ";

                    }

                    Console.WriteLine(txt);

                    //string driveName = e.NewEvent.Properties["DriveName"].Value.ToString();

                    //EventType eventType = (EventType)(Convert.ToInt16(e.NewEvent.Properties["EventType"].Value));

                    //string eventName = Enum.GetName(typeof(EventType), eventType);

                    //Console.WriteLine("{0}: {1} {2}", DateTime.Now, driveName, eventName);

                };

                watcher.Query = query;

                watcher.Start();

                //Console.ReadKey();

            }

  • 相关阅读:
    动与静
    ASP.NET 2.0 Membership
    又是asp.net 2.0的一个奇怪异常
    Cool tool !ASP.NET AJAX JavaScript Class Browser
    UserFul Methods
    中秋快乐
    Windows Vista RTM
    asp.net 2.0 下的表单验证Cookieless属性
    DataTable 内部索引已损坏:"4"
    asp.net 2.0 用户管理功能结构
  • 原文地址:https://www.cnblogs.com/bruce1992/p/14838921.html
Copyright © 2011-2022 走看看