473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Register insertion of USB drives in .NET 1.1

Hi there,

I'm trying to write something in VB.NET that registers the insertion of a
USB device (specifically a USB flash drive) and acts upon the event. I've
done some reading up and it seems that using ManagementEventWatchers is the
way to go, yet using the code below in a test project, I find that inserting
a USB drive triggers up to about 5 events instead of just the 1 I'm
expecting.

If anyone could point out the error of my ways that'd be great.

Cheers

Paul Taylor
Imports System.management
Public Class Form1
Inherits System.Windows.Forms.Form
...
Dim query As WqlEventQuery
Dim WithEvents watch As ManagementEventWatcher
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
query = New WqlEventQuery("Select * from Win32_DeviceChangeEvent")
watch = New ManagementEventWatcher(query)
watch.Start()
End Sub

Private Sub w_EventArrived(ByVal sender As Object, ByVal e As
System.Management.EventArrivedEventArgs) Handles watch.EventArrived
MsgBox("Event!")
End Sub
End Class
Feb 1 '06 #1
1 2020
This might help:
http://www.developerfusion.co.uk/show/4392/

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Paul Taylor" wrote:
Hi there,

I'm trying to write something in VB.NET that registers the insertion of a
USB device (specifically a USB flash drive) and acts upon the event. I've
done some reading up and it seems that using ManagementEventWatchers is the
way to go, yet using the code below in a test project, I find that inserting
a USB drive triggers up to about 5 events instead of just the 1 I'm
expecting.

If anyone could point out the error of my ways that'd be great.

Cheers

Paul Taylor
Imports System.management
Public Class Form1
Inherits System.Windows.Forms.Form
...
Dim query As WqlEventQuery
Dim WithEvents watch As ManagementEventWatcher
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
query = New WqlEventQuery("Select * from Win32_DeviceChangeEvent")
watch = New ManagementEventWatcher(query)
watch.Start()
End Sub

Private Sub w_EventArrived(ByVal sender As Object, ByVal e As
System.Management.EventArrivedEventArgs) Handles watch.EventArrived
MsgBox("Event!")
End Sub
End Class

Feb 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Travis L. Alltop | last post by:
All, To make a long story short, we are swapping out the "knock-off" drives that the NA purchased on E-Bay in one of our production SQL Servers (SQL Server 2000 Enterprise) this weekend for...
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
36
by: Ron Johnson | last post by:
http://hardware.devchannel.org/hardwarechannel/03/10/20/1953249.shtml?tid=20&tid=38&tid=49 -- ----------------------------------------------------------------- Ron Johnson, Jr....
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
0
by: Dennis | last post by:
I have tried to use the IWshRuntimeLibrary and ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk") to get all Logical Drives, Mapped Network Drives, Shared Folders and Shared Drives with...
2
by: ImOk | last post by:
WHen I run this under Windows I get the Count of drives but then I get an error message on the Reset() when I try to enumerate. Does this work for anyone? $fs = new...
4
by: Andrix | last post by:
Hi, I have a table with 20.000.000 of tuples. I have been monitoring the performance of the insertion and updates, but not convince me at all. The table have 30 columns, what and 12 of it, are...
0
by: polocar | last post by:
Hi, I have noticed a strange behaviour of CurrencyManager objects in C# (I use Visual Studio 2005 Professional Edition). Suppose that you have a SQL Server database with 2 tables called "Cities"...
9
by: python_newbie | last post by:
I don't know this list is the right place for newbie questions. I try to implement insertion sort in pyhton. At first code there is no problem. But the second one ( i code it in the same pattern i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.