Block/Unblock USB Ports in windows using VB.NET


In vb.NET, it is possible to control the port of windows, by editing the values in the local registry.

Below are two functions that can be used to block and unblock USB ports using VB.NET.

First, you need to import namespace below:

Imports Microsoft.Win32
Note: The application that you are creating needs to runĀ as an administrator in order to access the registry and change the values

Disable/Block USB Port using VB.NET

Private Sub BlockUSPPort()
    Dim regKey As RegistryKey
    regKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR", True)
    regKey.SetValue("Start", 4) ' value 4 is to disable the port
End Sub

Enable/Unblock USB Port using VB.NET

Private Sub UnblockUSBPort()
   Dim regKey As RegistryKey
   regKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR", True)
   regKey.SetValue("Start", 3) ' value 3 is to disable the port
End Sub

Happy Codding!

Related Articles

Introduction to Numeric Functions in vb.net

Function to calculate the difference between two dates using VB.NET

Create system tray icon in windows forms application using C# and VB.Net

Feras Sh

About Feras Sh

Software Engineer

View all posts by Feras Sh →

Leave a Reply