Xx...Tazer...xX Owner
Posts : 1239 T®ue Points : 1102678 T®ue Reputation : 40 Join date : 2009-09-02 Age : 31 Location : Chicago,Illinois
| Subject: [VB.NET]USB Access Tue Oct 26, 2010 6:05 am | |
| Now this isn't something I came up with, something I had to look into and have used it for a few things, on it's own it's pretty buggy and you can't do anything more then view the folders /files AFTER you plug the device in. - Code:
-
Imports System.IO Imports System.Runtime.InteropServices
Public Class Form1 Private Const WM_DEVICECHANGE As Integer = &H219 Private Const DBT_DEVICEARRIVAL As Integer = &H8000 Private Const DBT_DEVTYP_VOLUME As Integer = &H2
'Device information structure Public Structure DEV_BROADCAST_HDR Public dbch_size As Int32 Public dbch_devicetype As Int32 Public dbch_reserved As Int32 End Structure 'Volume information Structure Private Structure DEV_BROADCAST_VOLUME Public dbcv_size As Int32 Public dbcv_devicetype As Int32 Public dbcv_reserved As Int32 Public dbcv_unitmask As Int32 Public dbcv_flags As Int16 End Structure '<<<< Function that gets the drive letter from the unit mask >>>> Private Function GetDriveLetterFromMask(ByRef Unit As Int32) Dim i As Integer For i = 0 To 25 If Unit And i Then Exit For Unit = Unit >> 1 Next Return Chr(i + Asc("A")) End Function
'Override message processing to check for the DEVICECHANGE message Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If m.Msg = WM_DEVICECHANGE Then If m.WParam = DBT_DEVICEARRIVAL Then Dim DeviceInfo As DEV_BROADCAST_HDR DeviceInfo = Marshal.PtrToStructure(m.LParam, GetType(DEV_BROADCAST_HDR)) If DeviceInfo.dbch_devicetype = DBT_DEVTYP_VOLUME Then Dim Volume As DEV_BROADCAST_VOLUME Volume = Marshal.PtrToStructure(m.LParam, GetType(DEV_BROADCAST_VOLUME)) Dim DriveLetter As String = (GetDriveLetterFromMask(Volume.dbcv_unitmask) & ":") Dim Files() As String = Directory.GetDirectories(DriveLetter) Dim filesnames() As String = Directory.GetFiles(DriveLetter) Dim Filename As String Dim file As String
For Each Filename In Files ListView1.BeginUpdate() ListView1.Items.Add(Filename) ListView1.EndUpdate() ListView1.Refresh() Next For Each file In filesnames ListView1.BeginUpdate() ListView1.Items.Add(file) ListView1.EndUpdate() ListView1.Refresh() Next 'Dim di As DirectoryInfo = Directory.CreateDirectory(path) End If End If End If MyBase.WndProc(m) End Sub End Class | |
|
Always_Jonezen Site Admin
Posts : 155 T®ue Points : 1015049 T®ue Reputation : 8 Join date : 2010-01-25 Age : 47 Location : NC
| Subject: Re: [VB.NET]USB Access Tue Oct 26, 2010 11:35 am | |
| this looks like the plist in my iphone u can customize some of the strings | |
|