1

I an trying to write a simple Windows Service that shall detect any incoming USB device and Launch a GUI application.

            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

http://www.codeproject.com/Articles/63878/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?

EDIT 1: Presently there is no solution that works on win XP when we put the code in windows service.

Kind Regards

Bharat

4

1 回答 1

1

您可以简单地使用这两种解决方案,然后根据您使用的 Windows 版本使用适当的解决方案。

使用该System.Environment.OSVersion属性告诉您您使用的是哪个版本的 Windows,然后如果它早于 Windows 7,则执行 CodeProject 解决方案,如果它是 Windows 7 或更高版本,则执行其他解决方案。

您可以在此处阅读有关System.Environment.OSVersion酒店回复您的信息的更多信息。

于 2013-04-04T12:23:51.477 回答