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

Last modified: February 22, 2019

Comments

Write a Reply or Comment

Your email address will not be published.