0

I got this problem while trying to disable or enable ports. It works well when Im using my friend's laptop but when I tried using my laptop, it give this error. Why was this happen and how to solve it? Thanks ^^

Private Sub DisableBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisableBtn.Click
        Microsoft.Win32.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start", 4, Microsoft.Win32.RegistryValueKind.DWord) 'this line gives error
        MessageBox.Show("Port are disable", "USB Disable", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Me.Hide()
        Login.Show()
    End Sub
    Private Sub EnableBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnableBtn.Click
        Microsoft.Win32.Registry.SetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start", 3, Microsoft.Win32.RegistryValueKind.DWord) 'this line gives error
        MessageBox.Show("Port are enable", "USB Enable", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Me.Hide()
        Login.Show()
    End Sub
asa
  • 1
  • 6
  • 1
    By default, the keys in `HKEY_LOCAL_MACHINE` are writable only by administrators. It's likely your friend is logged in as an administrator, while you are not. Alternatively, your friend might have changed the permissions on those keys. – RB. Sep 30 '16 at 14:55
  • oh so I need to have administrator right to solve this problem? – asa Sep 30 '16 at 14:57
  • 1
    You can run as administrator, or give yourself access to those keys, yes. You can use`regedit` to give yourself write access to just those keys - just right-click on the key and click `Permissions...`. Don't give yourself more access than you actually require though, as that opens you up to security vulnerabilities (see Principle-of-least-privilege) – RB. Sep 30 '16 at 14:58
  • okay thank you for the reply ^^ – asa Sep 30 '16 at 15:19

0 Answers0