如何检测和阻止USB设备

时间:2014-04-23 08:37:08

标签: vb.net

我正在开发一个用于在连接时检测和阻止可移动USB设备的项目。 我只需要扫描连接的USB设备的代码。

2 个答案:

答案 0 :(得分:1)

获取devcon

   process.start("devcon /r disable USB*")

更容易

答案 1 :(得分:0)

Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
    Dim regKey As RegistryKey
    Dim ver As Decimal
    'opens the path USBSTOR from regedit
    If rbtnDisable.Checked Then
        If MsgBox("All USB Ports Will Be Disabled Except The Presently Connected Ports (Ex.,USB Mouse,Printer etc !) ", MsgBoxStyle.OkCancel, "ARE YOU SURE ?!") = MsgBoxResult.Ok Then
            regKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR", True)
            regKey.SetValue("Start", 4) ' 4(To disable the ports)
        End If
    Else
        regKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR", True)
        regKey.SetValue("Start", 3) ' 3(To enable the ports)
        MsgBox("Ports Are Enabled !", MsgBoxStyle.OkOnly)

    End If
End Sub

我将此代码用于block/enable USB Port(s)

并参考12链接以检测USB驱动器