Plug and Play

  • Thread starter Thread starter Brad Markisohn
  • Start date Start date
B

Brad Markisohn

Is there a way to determine, programmatically, when Plug-and-Play devices
are connected or removed from the PC? In VB 6 I caught events from the
SysInfo control, but I don't believe that this control is supported in .Net.
Any suggestion?

TIA

Brad
 
Hi Brad,

You may take a look at the link below.
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=O90u7Tcr
CHA.1668%40TK2MSFTNGP09&rnum=2&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%2
6oe%3DUTF-8%26q%3DSysInfo%2B%2522vb.net%2522%2B%2522plug%2Band%2Bplay%2522

If you have any concern on this issue,please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Peter,

Thanks for reminding me that I'd already posted this question a year ago. I
solved the problem differently on that project, but now I'm back to needing
the solution.

Thanks

Brad
 
Hi Brad,

Here is a sample.
'===========================================================================
=====
Dim watcher As System.Management.ManagementEventWatcher

Public Sub StartListen()
watcher = New System.Management.ManagementEventWatcher
watcher.Query = New System.Management.EventQuery("SELECT * FROM
__InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA
'Win32_PnPEntity'")
AddHandler watcher.EventArrived, AddressOf NewPlugPlay
watcher.Start()
End Sub
Public Sub StopListen()
watcher.Stop()
End Sub
Public Sub NewPlugPlay(ByVal sender As Object, ByVal e As
EventArrivedEventArgs)

Console.WriteLine("New Plug and Play = " +
(CType(e.NewEvent("TargetInstance"), ManagementBaseObject))("Caption"))
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
StartListen()
End Sub
'===========================================================================
=====

If you have any concern on this issue,please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top