tags:

views:

458

answers:

1

I'm working on an application that needs to temporarily put a machine into a restricted, kiosk-like state. One of the things I need to block is access to attached USB drives. Is there any way to do this, via C#, other than messing with Windows group policy? (That approach is covered by my other SO question on this topic)

I realize there might be security implications of this, and I might need admin rights to the box, and that's OK. At this point I just need pointed in the right direction to continue my research.

Update:

I'm targeting Windows XP for this. Vista support would be nice, but not required. ideally I would only block USB drives plugged in after my app starts up, but it's acceptable to block ALL USB drive access.

This application will be run on machines I do not control. Basically my app gets installed, creating a restricted sandbox. The user then logs into my app, performs some timed actions, and then logs out. My app is them removed, restoring the PC to its prior state. I'm looking for a code-based solution that enables me to make the fewest number of assumptions about the pre-existing environment, up to and including the assumption that I can access the BIOS.

+5  A: 

You can do this by modifying the registry.

using Microsoft.Win32;
RegistryKey key;
key = Registry.LocalMachine.OpenSubKey
         ("SYSTEM\\CurrentControlSet\\Services\\UsbStor");
key.SetValue("Start", 4, RegistryValueKind.DWord);  //disables usb drives
key.SetValue("Start", 3, RegistryValueKind.DWord);  //enables usb again

http://support.microsoft.com/kb/823732

Any devices already connected will remain there, but no new usb drives plugged in will be automatically mounted.

sparks
According to this article (http://diaryproducts.net/about/operating_systems/windows/disable_usb_sticks) this only works if a USB storage driver is already installed. If a drive is NOT already installed then the Plug-N-Play infrastructure will install it on first use, and that install will reset this registry key to "3" [allowed]. Have you encountered this issue? Do you have any ideas on how to address it, other than restricting access to USBSTOR.INF per the linked article?
Seth Petry-Johnson
I'd probably eat the one time hit that it works during your app unless it is absolutely critical. You're ok with something already plugged in working so I'd accept that case as the exception. Either that or distribute your app on USB sticks and sticks and kill the exception case.
sparks