PDA

View Full Version : سوال: چطور میشه به usb دیتا فرستاد؟



nima898
چهارشنبه 06 آبان 1388, 12:03 عصر
سلام
چطور میشه به usb دیتا فرستاد؟

milad.biroonvand
چهارشنبه 06 آبان 1388, 13:24 عصر
System.Management


Public


Class Form1


Dim w As ManagementEventWatcher


Private Sub AddUSBHandler()


Dim q As WqlEventQuery


Dim scope As ManagementScope = New ManagementScope("root\CIMV2") scope.Options.EnablePrivileges =

True

Try
q =

New WqlEventQuery() q.EventClassName =

"__InstanceOperationEvent"
q.WithinInterval =

New TimeSpan(0, 0, 1) q.Condition =

"TargetInstance ISA 'Win32_USBControllerdevice'"
w =

New ManagementEventWatcher(scope, q)


AddHandler w.EventArrived, AddressOf USBEvent w.Start()



Catch ex As Exception MessageBox.Show(ex.Message)


If Not w Is Nothing Then
w.Stop()

End If

End Try


End Sub



Public Sub USBEvent(ByVal sender As System.Object, ByVal e As EventArrivedEventArgs)

If e.NewEvent.ClassPath.ClassName = "__InstanceCreationEvent" Then

Dim s As String
s += e.NewEvent.Properties(

"TargetInstance").Value.Properties("Antecedent").Value.ToString() + ControlChars.CrLf s += e.NewEvent.Properties(


"TargetInstance").Value.Properties("Dependent").Value.ToString() + ControlChars.CrLf MsgBox(


"USB inserted, the information is " + ControlChars.CrLf + s)

ElseIf e.NewEvent.ClassPath.ClassName = "__InstanceDeletionEvent" Then

Dim s As String
s += e.NewEvent.Properties(

"TargetInstance").Value.Properties("Antecedent").Value.ToString() + ControlChars.CrLf s += e.NewEvent.Properties(


"TargetInstance").Value.Properties("Dependent").Value.ToString() + ControlChars.CrLf MsgBox(


"USB removed, the information is " + s)

Else
MsgBox(e.NewEvent.ClassPath.ClassName)

End If

End Sub


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddUSBHandler()


End Sub


Private Sub Form1_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed

If Not w Is Nothing Then
w.Stop()

End If


End Sub End