2011-08-29 25 views
1

可能重複:
Looking for C# code for detecting removable drive (usb flash)如何使用FileSystemWatcher的監測新的驅動器

怎能System.IO.FileSystemWatcher類可用於檢測(如F :)連接/斷開下的驅動器視窗?如果這是不可能的,還可以採用其他事件驅動的方式(除了輪詢DriveInfo.GetDrives())?

在此先感謝。

+6

StackOverflow rocks:http://stackoverflow.com/questions/715739/looking-for-c-code-for-detecting-removable-drive-usb-flash –

回答

0

我寫了一個使用System.Management.ManagementEventWatcher和WMI類Win32_VolumeChangedEvent浮出水面,你可能對PowerShell中覆蓋設備移除,添加等註冊新的事件,一個PowerShell模塊你應該能夠從我的這個博客帖子找出相關的管道:

http://www.nivot.org/nivot2/post/2008/08/16/AutoMountunmountNewPSDrivesForRemovableDrivesAndNetworkSharesInPowerShellV2.aspx

你應該能夠使用我在上面的腳本中使用的方法在少於十行的C#中爲新驅動器連接一個事件。

希望這會有所幫助。

相關問題