检测到USB时执行一些操作C# [英] perform some action when usb is detected c#

查看:94
本文介绍了检测到USB时执行一些操作C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发应用程序,现在我想检测USB设备(大量存储),但是我需要做的是捕获该消息并将其不传递给Windows.我想问一个密码,如果还可以的话,我想将消息传递给Windows,否则将其丢弃,我该如何做到这一点,>

I have been developing an application and i want to detect usb devices(MASS STORAGE) now that i have done but what i need to do is to capture that message and dont pass it to the windows. i want to ask a password and if that''s ok then i want to pass the message to the windows otherwise discard it,,,how can i accomplish that,,,>

protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case Win32.WM_DEVICECHANGE: OnDeviceChange(ref m); break;
}
base.WndProc (ref m);
}

void OnDeviceChange(ref Message msg)
{
int wParam = (int)msg.WParam;
if (wParam == Win32.DBT_DEVICEARRIVAL)
{
    label1.Text = "Arrival";
    //MessageBox.Show("" + wParam);
    //msg = Message.Create(new IntPtr(),1,new IntPtr(),new IntPtr());
}
else if (wParam == Win32.DBT_DEVICEREMOVECOMPLETE) label1.Text =
 "Remove";
}

推荐答案



如果要阻止所有USB设备(大容量存储),请阅读此解决方案.

禁用/启用USB阻止后重新扫描USB设备-通过注册表 [使用C#开发USB存储设备保护工具 [ ^ ]

另一种方法是将应用程序锁定在DeviceArrival,读取连接设备的VID/PID,将其阻止,要求输入密码,如果密码正确,则将其取消阻止.

希望有帮助.

问候
Hi,

if you want to block all usb devices (mass storage), please read this solution.

Re-Scanning USB Devices after disabling/enabling USB-Block-By-Registry[^]

CP-Article:
Developing a USB Storage Device Protection Tool with C#[^]

Another way could be to lock your application at DeviceArrival, read the VID/PID of attached device, block it, ask for password and if it''s correct, unblock it.

Hope that helps.

Regards


这篇关于检测到USB时执行一些操作C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆