const int WM_DEVICECHANGE =
const int DBT_DEVICEARRIVAL =
const int DBT_DEVICEREMOVECOMPLETE =
protected override void WndProc(ref Message m)
{
try
{
//if (m
//{
switch (m
{
case DBT_DEVICEARRIVAL: // U盤插入
DriveInfo[] s = DriveInfo
foreach (DriveInfo drive in s)
{
if (drive
{
Console
break;
}
}
break;
case DBT_DEVICEREMOVECOMPLETE: //U盤卸載
//
Console
break;
default:
break;
}
//}
}
catch (Exception ex)
{
MessageBox
}
base
}
From:http://tw.wingwit.com/Article/program/net/201311/14053.html