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

Developer technologies | Windows Forms
Developer technologies | VB
0 comments No comments

Answer accepted by question author
Xingyu Zhao-MSFT 5,381 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.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Newest
  1. Castorix31 91,971 Reputation points
    2021-06-28T08:25:21.32+00:00

    With SetupDiSetClassInstallParams + SetupDiCallClassInstaller in x64

    Many samples on Google

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.