How to change a registry key using VB.NET or VB6?

I need to edit the registry key and set the data value to "4"

I know how to do this using the command line, but I'm trying to find Visual Basic code for this.

If this helps, this is the key:

HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ USBSTOR \ Start

+3
source share
3 answers

This is how you did it in Visual Basic.NET.

Dim key As RegistryKey = Registry.LocalMachine Dim subkey As RegistryKey subkey = key.OpenSubKey("SYSTEM\CurrentControlSet\Services\USBSTOR", True) subkey.SetValue("Start", 4) 

You will need to add

 Imports System Imports Microsoft.Win32 

at the top of the code.

+3
source

Here you can do it in Visual Basic 6 (or VBA)

Download the registry editing code and place it in the class.

Then, to actually change the value, you can use the following code:

 Dim reg As New RegistryClass With reg .SetKeyValue .HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\USBSTOR", .RegDWORD, "Start", 4 End With 
+2
source

You need to use the Registry class in the Microsoft.Win32 namespace. Check documents, it is quite easy to use.

0
source

Source: https://habr.com/ru/post/1397939/


All Articles