代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
usb 识别
作者:
dezai
/ 发布于
2014/2/21
/
504
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.IO; using System.Windows.Forms; using System.Runtime.InteropServices; namespace USB { public partial class USB : Form { public USB() { InitializeComponent(); } public const int WM_DEVICECHANGE = 0x219; public const int DBT_DEVICEARRIVAL = 0x8000; public const int DBT_CONFIGCHANGECANCELED = 0x0019; public const int DBT_CONFIGCHANGED = 0x0018; public const int DBT_CUSTOMEVENT = 0x8006; public const int DBT_DEVICEQUERYREMOVE = 0x8001; public const int DBT_DEVICEQUERYREMOVEFAILED = 0x8002; public const int DBT_DEVICEREMOVECOMPLETE = 0x8004; public const int DBT_DEVICEREMOVEPENDING = 0x8003; public const int DBT_DEVICETYPESPECIFIC = 0x8005; public const int DBT_DEVNODES_CHANGED = 0x0007; public const int DBT_QUERYCHANGECONFIG = 0x0017; public const int DBT_USERDEFINED = 0xFFFF; // 逻辑卷标 public const int DBT_DEVTYP_VOLUME = 0x00000002; // private LockScreen Ls = new LockScreen(); public string ID=""; public string Value; public string[] item; [StructLayout(LayoutKind.Sequential)] public struct DEV_BROADCAST_VOLUME { public int dbcv_size; public int dbcv_devicetype; public int dbcv_reserved; public int dbcv_unitmask; } protected override void WndProc(ref Message m) { try { if (m.Msg == WM_DEVICECHANGE) { switch (m.WParam.ToInt32()) { case WM_DEVICECHANGE: break; case DBT_DEVICEARRIVAL://U盘有插入 this.timer1.Enabled = true; DriveInfo[] s = DriveInfo.GetDrives(); foreach (DriveInfo DriveI in s) { if (DriveI.DriveType == DriveType.Removable) { // Ls.Show(); // this.Hide(); // MessageBox.Show("sss"); break; } int devType = Marshal.ReadInt32(m.LParam, 4); if (devType == DBT_DEVTYP_VOLUME) { DEV_BROADCAST_VOLUME vol; vol = (DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME)); ID=vol.dbcv_unitmask.ToString("x"); this.Text = IO(ID); this.Tag = IO(ID); //if (item.Length ==0||IO(ID)!=this.Tag.ToString ()) //{ //} } this.label1.Text = this.Text; } break; case DBT_CONFIGCHANGECANCELED: break; case DBT_CONFIGCHANGED: break; case DBT_CUSTOMEVENT: break; case DBT_DEVICEQUERYREMOVE: break; case DBT_DEVICEQUERYREMOVEFAILED: break; case DBT_DEVICEREMOVECOMPLETE: //U盘卸载 DriveInfo[] I = DriveInfo.GetDrives(); foreach (DriveInfo DrInfo in I) { int devType = Marshal.ReadInt32(m.LParam, 4); if (devType == DBT_DEVTYP_VOLUME) { DEV_BROADCAST_VOLUME vol; vol = (DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(m.LParam, typeof(DEV_BROADCAST_VOLUME)); ID = vol.dbcv_unitmask.ToString("x"); this.Text = IO(ID) + "盘退出!\n"; } this.label1.Text += this.Text; // MessageBox.Show("U盘已经卸载", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case DBT_DEVICEREMOVEPENDING: break; case DBT_DEVICETYPESPECIFIC: break; case DBT_DEVNODES_CHANGED: break; case DBT_QUERYCHANGECONFIG: break; case DBT_USERDEFINED: break; default: break; } } } catch (Exception ex) { throw new Exception(ex.Message); } base.WndProc(ref m); } private void USB_Load(object sender, EventArgs e) { } public string IO(string ff) { switch (ff) { case "1": Value="A:"; break; case "2": Value= "B:"; break; case "4": Value= "C:"; break; case "8": Value= "D:"; break; case "10": Value= "E:"; break; case "20": Value= "F:"; break; case "40": Value= "G:"; break; case "80": Value= "H:"; break; case "100": Value= "I:"; break; case "200": Value= "J:"; break; case "400": Value= "K:"; break; case "800": Value= "L:"; break; case "1000": Value= "M:"; break; case "2000": Value= "N:"; break; case "4000": Value= "O:"; break; case "8000": Value= "P:"; break; case "10000": Value= "Q:"; break; case "20000": Value= "R:"; break; case "40000": Value= "S:"; break; case "80000": Value= "T:"; break; case "100000": Value= "U:"; break; case "200000": Value= "V:"; break; case "400000": Value= "W:"; break; case "800000": Value= "X:"; break; case "1000000": Value= "Y:"; break; case "2000000": Value= "Z:"; break; default: break; } return Value; } private void timer1_Tick(object sender, EventArgs e) { // this.Text = ID; } private void USB_Load_1(object sender, EventArgs e) { } } }
试试其它关键字
usb
识别
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
dezai
贡献的其它代码
(
1065
)
.
双色球
.
列出所有物理网络适配器
.
快乐数的 Python 实现
.
计算当月还剩天数
.
猜属相
.
二十四小时时钟
.
每日一语
.
很酷的日历
.
超长日历表单
.
最简单的时钟
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3