Avatar of Showkatdar
Showkatdar
 asked on

Detect USB through VB 6 Code

Dear,
How can we detect usb is plugged using visual basic 6. I want to send a simple note to my application as soon as usb is plugged in machine using vb6.
Hope i will get best answer from you.
Thank you and regards

Visual Basic ClassicChat / IM

Avatar of undefined
Last Comment
at_the_biginning

8/22/2022 - Mon
Showkatdar

ASKER
Is there any way in vb6 to detect usb as it is plugged in
ASKER CERTIFIED SOLUTION
Showkatdar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
at_the_biginning


Make reference to: Microsoft Scripting Runtime

Then add a ListBox to the project
Now add this code to the project:

Private Sub Form_Load()
Call Check
End Sub

Private Sub SysInfo1_DeviceArrival(ByVal DeviceType As Long, ByVal DeviceID As Long, ByVal DeviceName As String, ByVal DeviceData As Long)
Call Check
End Sub

Private Sub SysInfo1_DeviceRemoveComplete(ByVal DeviceType As Long, ByVal DeviceID As Long, ByVal DeviceName As String, ByVal DeviceData As Long)
Call Check
End Sub

Sub Check()
Dim FSO As New Scripting.FileSystemObject, drv As Scripting.Drive
List1.Clear
For Each drv In FSO.Drives
If drv.IsReady Then
If drv.DriveType = Removable Then
List1.AddItem drv.DriveLetter & ":"
End If
End If
Next
End Sub

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy