Project Description

This project is an easy to use wrapper for native Windows device management and device setup functions. You can use the library for querying device configuration, registering for device change notifications or sending I/O control codes to device drivers. It´s an experimental project, which enables .NET-developers, who want to avoid the use of WMI, to add device management capabilities to Windows applications. The project is written in C#.

Quick Start

The library can be used, if you want detect devices or device changes in your application (for instance, if the user is plugging or un-plugging a mass storage device). The good news is, you don´t have to deal with details of unmanaged code. The code works both for 32- and 64 bit operating systems. The following quick start example shows a simple Windows Forms application, which registers for device change notifications (you can find more examples in the documentation).

using System;
using System.Windows.Forms;
using DeviceManagement;

namespace WindowsFormsSample
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);

			InitializeDeviceNotifications();
		}

		private void InitializeDeviceNotifications()
		{
			var notificationHandler = new VolumeNotificationHandler();

			notificationHandler.VolumeArrival += this.OnVolumeArrival;
			notificationHandler.VolumeRemoveComplete += this.OnVolumeRemoveComplete;

			var deviceNotification = new DeviceNotification() { NotificationHandler = notificationHandler };

			deviceNotification.Register(DeviceType.LogicalVolume);

			this.components.Add(deviceNotification);
		}


		void OnVolumeRemoveComplete(object sender, DeviceNotificationEventArgs e)
		{
			Volume volume = e.GetVolume();

			MessageBox.Show(string.Format("Drive {0}: was removed.", volume.DriveLetter));
		}

		void OnVolumeArrival(object sender, DeviceNotificationEventArgs e)
		{
			Volume volume = e.GetVolume();

			MessageBox.Show(string.Format("Drive {0}: was successfully added.", volume.DriveLetter));
		}
	}
}

Last edited Dec 20, 2012 at 11:44 AM by mfriedrich, version 6