views:

57

answers:

1

Hello, I want to block a USB based on volume using C#. Like I want to block USB stick if capacity is greater than 8GB.

Look there is a method to block USB on PC using registry. but this will make USB undetectable so I can not get volume information.

I want to do that If my client program is running on some machine and I put restriction that USB capacity >=8GB should be restricted, so my C# code should safely remove the USB and should now show any balloon, I mean silently remove it.

+1  A: 

If you are disabling the USBSTOR key, then you prevent "ACCESS" to it, that includes gathering information from it.

I suggest you look here: WM_DEVICECHANGE

Using this you can catch when the USB is entered and then get the drive letter and use the DEV_BROADCAST_VOLUME to gather information on it, then you can disable it using your registry method.

kyndigs
Since the question is tagged as C#, it would be good to know if there are .NET equivalents for these Win32 events too.
Programming Hero
You can use the System.Management namespace shown here: http://msdn.microsoft.com/msdnmag/issues/02/05/WMIMan/default.aspx
kyndigs
Furthermore how to get the Event of Inserting USB so that my program get activated?
Aizaz
Look here for some examples: http://stackoverflow.com/questions/3772337/drive-is-mounted-or-changes-state-wm-devicechange-for-net
kyndigs
I have found very interesting article have a look please http://www.codeproject.com/KB/system/usbeject.aspx
Aizaz