Bashar Kokash' Blog

.Net Framework, windows and web development.

This site




  • MaximumASP

February 2008 - Posts

Webcast: Web development using Visual Studio 2008 By Vishal R. Joshi

Yesterday I atteneded this webcast that was dedicated for the new features in Visual Studio 2008.

Vishal R. Joshi presented the following topics:

  • Multitargeting.
  • Cascade Style Sheets Css.
  • The New ListView control.
  • Asynchrounons javascript.
  • Javascript intellisence and debugging.
  • LINQ to SQL
  • AJAX.

You can watch this webcast again here

Silverlight 2
A couple of days ago, Scott Guathrie gave a brief introduction to the new version of silverlight 2, he discussed the new features, and provided a couple of tutorials.


Windows Card Space on ASP.NET Wiki

There are a lot of resources about Windows Card Space on the Internet.

I collected some of those good resources: articles, books, blogs, forms, samples and videos on a single article on ASP.NET Wiki article.

Downloadable Hotfix: Performance and Editor fixes for Microsoft Visual Studio 2008 and Visual Web Developer Express 2008

As a response to the feedback on the performance of Visual Studio 2008 and Visual Web developer, Microsoft releases a new hot-fix which patches some of the editor and performance issues.


 You can download the hot-fix here.

 You can see a list of bugs that are fixed by this patch here

Visual Studio Gallery

Microsoft just release this new website for all of the Visual Studio extensions categories, check it out

USB Port Insert / Remove detection using WMI

Almost all modern peripheral devices use the USB port as an interface to connect to the pc. This post will show how to detect an insertion or removal of a device in a USB port.

I will use the Windows Management Instrumentation (WMI) which is a component of the Windows operating system that allows you to programmatically access management information in an enterprise environment.

First we should add the System.Management name space as a reference to our project

The add: using System.Management;

When a USB device is inserted a 'Win32_USBControllerdevice' record is added to the operating system's metabase and when the device is removed, that record will be deleted.

So we have to add two events to the same record and these events are "__InstanceCreationEvent" for insertion and "__InstanceDeletionEvent"  for removal.

The following method "AddHandler()" adds an event handler that is fired when a USB device is inserted.

//used to subscribes to temporary event notifications based on a specified event query.
ManagementEventWatcher w=null;

void AddUSBHandler()
	WqlEventQuery q;// Represents a WMI event query in WQL format (Windows Query Language)

ManagementScope scope = new ManagementScope("root\\CIMV2");

// Represents a scope (namespace) for management operations.

scope.Options.EnablePrivileges = true; try { q = new WqlEventQuery(); q.EventClassName = "__InstanceCreationEvent"; q.WithinInterval = new TimeSpan(0, 0, 3); q.Condition = @"TargetInstance ISA 'Win32_USBControllerdevice'"; w = new ManagementEventWatcher(scope, q); //adds event handler that’s is fired when the insertion event occurs w.EventArrived += new EventArrivedEventHandler(USBInseted); w.Start();//run the watcher } catch (Exception e) { MessageBox.Show(e.Message); if (w != null) w.Stop(); } FileStream FS = new FileStream(@”C:\USB_Log.txt”, FileMode.Append); StreamWriter SW = new StreamWriter(FS); public void USBInseted(object sender, EventArgs e) { SW.WriteLine("USB device is inserted at " + DateTime.Now.ToString()); } private void Form1_Load(object sender, EventArgs e) { AddUSBHandler(); }

Important note: you should stop the watcher before exiting the application or else an excption is thrown


private void Form1_FormClosing(object sender, FormClosingEventArgs e)
      if (w != null)
Now to add another handler for that fire when the USB device is removed all you have to do is just to set the EventClassName property of the WqlEventQuery object to “__InstanceDeletionEvent”.
Posted: Feb 06 2008, 09:39 PM by BasharKokash | with 2 comment(s)
Filed under: ,
Just Graduated

Tody I jus t got graduated from collage, I am now a computer systems engineer.

I'm so excited that now I will have enough time to get back to work with .NET technologies