Click here to Skip to main content
15,902,032 members
Please Sign up or sign in to vote.
1.60/5 (2 votes)
See more:
My idea is when you plug USB into the computer, the computer will get information of USB. If you have that information in the database, the computer will get USB. If not in the database, the computer does not get the USB.

Hepl me! Thanks!
Posted
Updated 14-Mar-10 13:38pm
v2

VB.NET
Private Const WM_DEVICECHANGE As Integer = &H219
   Private Const DBT_DEVICEARRIVAL As Integer = &H8000
   Private Const DBT_DEVICEREMOVECOMPLETE As Integer = &H8004
   Private Const DBT_DEVTYP_VOLUME As Integer = &H2

   Private Structure DEV_BROADCAST_VOLUME
        Dim Dbcv_Size As Integer
       Dim Dbcv_Devicetype As Integer
       Dim Dbcv_Reserved As Integer
       Dim Dbcv_Unitmask As Integer
       Dim Dbcv_Flags As Short
   End Structure




   Protected Overrides Sub WndProc(ByRef M As System.Windows.Forms.Message)
       On Error Resume Next

       If M.Msg = WM_DEVICECHANGE Then
           Select Case M.WParam
               Case DBT_DEVICEARRIVAL
                   Dim DevType As Integer = Marshal.ReadInt32(M.LParam, 4)
                   If DevType = DBT_DEVTYP_VOLUME Then
                       Dim Vol As New DEV_BROADCAST_VOLUME
                       Vol = Marshal.PtrToStructure(M.LParam, GetType(DEV_BROADCAST_VOLUME))

                       If Vol.Dbcv_Flags = 0 Then
                           For i = 0 To 20
                               If Math.Pow(2, i) = Vol.Dbcv_Unitmask Then
                                   Dim Usb As String = Chr(65 + i) + ":\"
                                   Msgbox (Usb)
                                   Exit For
                               End If
                           Next
                       End If
                   End If
           End Select
       End If
       MyBase.WndProc(M)
   End Sub
 
Share this answer
 
v2
You can't write C# or VB.NET code to 'reject' a USB drive. There are events that fire on the system level when a drive is added, and you can enumerate drives using System.IO.Drives, but you can't block a USB drive like that, AFAIK, not in .NET.
 
Share this answer
 
v2
Your idea is really great, if you are done doing that program, can you please share it with us? :)
 
Share this answer
 
v2
Try the DriveGate tool on this website tzitech. Email the author to receive a link to the download file.
 
Share this answer
 
I don't understand it, can you post example?
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Jul-14 13:14pm    
Not an answer at all. Will you stop it? You are abusing the forum on a regular basis.
—SA
In recent years he has tried without success. Now you introduce this software. Thank you very much!
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Jul-14 13:14pm    
Not an answer at all. Will you stop it? You are abusing the forum on a regular basis.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900