Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
How to detect an incoming USB device in windows Service on Windows XP machine?

Hello Experts,
I an trying to write a simple Windows Service that shall detect any incoming USB device and Launch a GUI application.
C#
WqlEventQuery query = new WqlEventQuery("SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 2");
watcher.EventArrived += watcher_EventArrived;
watcher.Query = query;
watcher.Start();
watcher.WaitForNextEvent();

This solution works well in Win 7 However, it fails in XP (I have XP SP3).

I found another solution here
Enumerate and Auto-Detect USB Drives[^]

This works very well in windows forms application even on windows XP, However it fails when I put it in service even on Win 7

Can you please help?

Kind Regards

Bharat
Posted
Updated 4-Apr-13 1:42am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900