How to Disable and Enable USB using VB.NET

Wilfred Eghenedji 326 Reputation points
2021-06-28T08:14:59.497+00:00

Sorry to ask, if am not violating the policy here: I need source code to enable and disable USB with a button using vb.net. The one have tried creating doesn't to work. Thank you

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,829 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,572 questions
0 comments No comments
{count} votes

Accepted answer
  1. Xingyu Zhao-MSFT 5,356 Reputation points
    2021-06-29T02:16:09.627+00:00

    Hi @Wilfred Eghenedji ,
    Also consider changing the registry value:

            ' Disable USB storage  
            Microsoft.Win32.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start", 4, Microsoft.Win32.RegistryValueKind.DWord)  
            ' Enable USB storage  
            Microsoft.Win32.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start", 3, Microsoft.Win32.RegistryValueKind.DWord)  
    

    Make sure you have administrator privileges.
    Best Regards,
    Xingyu Zhao
    *
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Castorix31 81,726 Reputation points
    2021-06-28T08:25:21.32+00:00

    With SetupDiSetClassInstallParams + SetupDiCallClassInstaller in x64

    Many samples on Google

    0 comments No comments