Jump to content
  • Advertisement
Sign in to follow this  
MTM

[.net] Enable/Disable USB port

This topic is 3585 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
According to this Microsoft KB article, there is a registry key for this.

To disable:
          Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\USBSTOR", true).SetValue("Start", 4);



To re-enable:
          Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\USBSTOR", true).SetValue("Start", 3);



However, the above code only for mass storage devices, not other devices such as keyboards and mice connected to the USB bus.

Share this post


Link to post
Share on other sites
There is no easy way to enable/disable hardware using C# that I know of. I remember because I looked up how to disable the NIC using C# and it required a bunch of complex things to be done. Since I was merely costing out how much it would be to code such a thing, I told my boss that it wasn't worth it. The registry key solution is best if that's what you're trying to do. Otherwise you might be better off using C++/CLI.

Share this post


Link to post
Share on other sites
There biggest chance is that the solution is there for you through the Win32 API in C. Which means, you'll have to P/Invoke the required functions/structures and then call those functions from your C# application.

It probably doesn't matter much if you write a C DLL that does all this stuff, and then P/Invoke the library's specific function on enabling/disabling the USB port or writing all the code in C#(However, I expect the code to be more simple in C).

Now, the question arises: Why do you want to disable USB ports? If you want to do this on a system scale because of security, why not look into hardware profiles or group policies? These are much more efficient at these things.

Toolmaker

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!