【问题标题】:Monitor When a USB Drive is connected with Visual Basic 10当 USB 驱动器与 Visual Basic 10 连接时的监视器
【发布时间】:2025-11-22 06:30:01
【问题描述】:

我正在寻找一种方法来监控闪存驱动器 (USB) 何时连接到我的电脑(Windows)。

我的第一个想法是在 Timer 中使用 System.IO.DriveInfo.GetDrives,并检查出现的新驱动器,但这可能对 CPU 的要求太高(我还没有这样做)

你们知道在 Visual Basic 10 中是否有更好的方法来做到这一点?

问候

【问题讨论】:

    标签: vb.net visual-studio-2010 usb vb.net-2010 usb-drive


    【解决方案1】:

    用途:

    <DllImport("user32.dll", SetLastError:=True)> _
    Public Shared Function RegisterDeviceNotification( _
      ByVal IntPtr As IntPtr, ByVal NotificationFilter As IntPtr, _
      ByVal Flags As Int32) As IntPtr
    End Function
    

    注册到 USB 插入通知。

    参考:MSDNanswer here

    【讨论】:

    • 谢谢,我能够在 Visual Basic 10 中使用声明函数,在代码顶部添加“Imports System.Runtime.InteropServices”,但我找不到任何使用示例它在基于 Windows 窗体的项目中。
    最近更新 更多