/*
* A simple app to demonstrates how to monitor the UsbControllerDevice for
* the arrival of creation/operation events
* Downloaded from
www.publicjoe.co.uk
*
* This software is provided 'as-is', without any express or implied
warranty.
* In no event will the author(s) be held liable for any damages arising
from
* the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely.
*/
using System;
using System.Management;
class WMIEvent
{
public static void Main()
{
WMIEvent we = new WMIEvent();
ManagementEventWatcher w= null;
WqlEventQuery q;
ManagementOperationObserver observer = new
ManagementOperationObserver();
// Bind to local machine
ManagementScope scope = new ManagementScope("root\\CIMV2");
scope.Options.EnablePrivileges = true; //set required privilege
try
{
q = new WqlEventQuery();
q.EventClassName = "__InstanceOperationEvent";
q.WithinInterval = new TimeSpan(0,0,3);
q.Condition = @"TargetInstance ISA 'Win32_DiskDrive' ";
w = new ManagementEventWatcher(scope, q);
w.EventArrived += new EventArrivedEventHandler(we.DiskEventArrived);
w.Start();
Console.ReadLine(); // block main thread for test purposes
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
w.Stop();
}
}
public void DiskEventArrived(object sender, EventArrivedEventArgs e)
{
//Get the Event object and display its properties (all)
foreach(PropertyData pd in e.NewEvent.Properties)
{
ManagementBaseObject mbo = null;
if(( mbo = pd.Value as ManagementBaseObject) != null)
{
Console.WriteLine("--------------Properties------------------");
foreach(PropertyData prop in mbo.Properties)
Console.WriteLine("{0} - {1}", prop.Name, prop.Value);
}
}
}
}"sanjana" <su****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
hi
can anyone help me with this
i want to write a code in c#.net which detects usb storage and media
card insertion
can anyone help me with this??
thanx