简体   繁体   English

如何使用C#限制对USB驱动器的访问?

[英]How to restrict access to USB drives using C#?

I'm working on an application that needs to temporarily put a machine into a restricted, kiosk-like state. 我正在开发一个应用程序,需要暂时将机器置于受限制的,类似于kiosk的状态。 One of the things I need to block is access to attached USB drives. 我需要阻止的一件事是访问连接的USB驱动器。 Is there any way to do this, via C#, other than messing with Windows group policy? 除了搞乱Windows组策略之外 ,有没有办法通过C#做到这一点? (That approach is covered by my other SO question on this topic ) 关于这个主题我的其他SO问题涵盖了这种方法)

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. 我的目标是Windows XP。 Vista support would be nice, but not required. Vista支持很不错,但不是必需的。 ideally I would only block USB drives plugged in after my app starts up, but it's acceptable to block ALL USB drive access. 理想情况下,我只会阻止我的应用程序启动插入的USB驱动器,但阻止所有USB驱动器访问是可以接受的。

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. 我的应用程序被删除,将PC恢复到以前的状态。 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. 我正在寻找一种基于代码的解决方案,使我能够对预先存在的环境做出最少的假设,包括我可以访问BIOS的假设。

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 http://support.microsoft.com/kb/823732

Any devices already connected will remain there, but no new usb drives plugged in will be automatically mounted. 已连接的任何设备将保留在那里,但不会自动安装插入的新USB驱动器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM