Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Imports Microsoft.Win32
Public Class Form1
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim regKey As RegistryKey
        'opens the path USBSTOR from regedit
        If RadioButton1.Checked Then
            If MsgBox("All USB Ports Will Be Disabled Except The Presently Connected Ports (Ex.,USB Mouse,Printer etc !) ", MsgBoxStyle.OkCancel, "ARE YOU SURE ?!") = MsgBoxResult.Ok Then
                regKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR", True)
                regKey.SetValue("Start", 4) ' 4(To disable the ports)
            End If
        Else
            regKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR", True)
            regKey.SetValue("Start", 3) ' 3(To enable the ports)
            MsgBox("Ports Are Enabled !", MsgBoxStyle.OkOnly)

        End If
    End Sub
End Class


I done this Bt i got a error on the below statement while run the application
C#
"regKey = Registry.LocalMachine.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR", True)"

please someone help me to correct this error... or someone please devlop a sample program and send the sourcecode please help me.. Thank You
Posted
Updated 15-Mar-15 4:41am
v3
Comments
ZurdoDev 15-Mar-15 12:24pm    
What's the error?
Member 11090857 15-Mar-15 22:44pm    
While Running it shows a error "Registered Registry Is not Allowed"
ZurdoDev 16-Mar-15 7:26am    
A quick google search shows that is a permissions issue.
barneyman 15-Mar-15 22:11pm    
elevation?
Maciej Los 16-Mar-15 3:41am    
Do you have admin privileges?

1 solution

Please, read my comment to the question.

You need to have admin privileges to be able to modify OS registry. To work around it, use DevCon command[^]. Here is an example in C#: http://programmersheaven.com/discussion/337951/programatically-enable--disable-usb-port-using-cnet[^]

Device Console (DevCon.exe) Examples[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900