Copy directory from USB to Desktop computer

  • Thread starter Thread starter mipakteh
  • Start date Start date
M

mipakteh

Guest
Hi All,

What I try to do;

When plugged in the USB pendrive it automaticallly copy directory from usb to desktop computer.

I browse at internet and find this code.When I run this code it nothing happen.Somebody can correct or show the true code.

thank.

Imports System
Imports System.IO
Imports System.Runtime.InteropServices

Public Class Form1

Private WM_DEVICECHANGE As Integer = &H219

Public Enum WM_DEVICECHANGE_WPPARAMS As Integer
DBT_CONFIGCHANGECANCELED = &H19
DBT_CONFIGCHANGED = &H18
DBT_CUSTOMEVENT = &H8006
DBT_DEVICEARRIVAL = &H8000
DBT_DEVICEQUERYREMOVE = &H8001
DBT_DEVICEQUERYREMOVEFAILED = &H8002
DBT_DEVICEREMOVECOMPLETE = &H8004
DBT_DEVICEREMOVEPENDING = &H8003
DBT_DEVICETYPESPECIFIC = &H8005
DBT_DEVNODES_CHANGED = &H7
DBT_QUERYCHANGECONFIG = &H17
DBT_USERDEFINED = &HFFFF
End Enum

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

If m.Msg = WM_DEVICECHANGE Then
Select Case m.WParam
Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEARRIVAL
Call ProcessUSB()
End Select
End If

MyBase.WndProc(m)

End Sub



Private Sub ProcessUSB()
For Each d As System.IO.DriveInfo In My.Computer.FileSystem.Drives
If d.DriveType = DriveType.Removable And d.IsReady Then
My.Computer.FileSystem.CopyDirectory(d.Name & ("VB_Black Screen"), "C:\Users\Uset\Desktop\VB_Black Screen\", True)
End If
Next

End Sub



End Class

Continue reading...
 
Back
Top