Hi Everyone, If you want to find an application for USB Disable. You don’t want someone plug their USB drive to your PC. It’s protect your PC from Virus.

So this article shows you how to create a USB disable VB.net project.

VB.net Contents:

In Windows, the path for preventing USB plugging into a PC allows access or doesn’t allow access. The path is

SYSTEM\CurrentControlSet\Services\USBSTOR

And in start (Type: REG_DWORD) default value is number 3, so this application will change to number 4.

Design Application

VB.net Code

Imports Microsoft.Win32
Public Class Form1
    Dim Str As String = My.Computer.Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR").ToString
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        My.Computer.Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR\Start")
        lblPath.Text = My.Computer.Registry.GetValue(Str, "Start", "Error")
        If lblPath.Text = 3 Then
            PictureBox1.Show()
            PictureBox2.Hide()
        Else
            PictureBox1.Hide()
            PictureBox2.Show()
        End If
    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        Registry.SetValue(Str, "Start", 4, RegistryValueKind.DWord)
        My.Computer.Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR\Start")
        lblPath.Text = My.Computer.Registry.GetValue(Str, "Start", "Error")
        If lblPath.Text = 3 Then
            PictureBox1.Show()
            PictureBox2.Hide()
        Else
            PictureBox1.Hide()
            PictureBox2.Show()
        End If
    End Sub

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
        Registry.SetValue(Str, "Start", 3, RegistryValueKind.DWord)
        My.Computer.Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR\Start")
        lblPath.Text = My.Computer.Registry.GetValue(Str, "Start", "Error")
        If lblPath.Text = 3 Then
            PictureBox1.Show()
            PictureBox2.Hide()
        Else
            PictureBox1.Hide()
            PictureBox2.Show()
        End If
    End Sub
End Class

Run your project as Administrator

After you completed coding, please right-click on your project and choose properties-> Application-> view Windows Settings-> app manifest (Change asInvoker to requireAdministrator).

Default line

<requestedExecutionLevel level="asInvoker" uiAccess="false" />

Line for running application as Administrator

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Final Result:

For more understanding, Watch a Video: