How can I edit a registry key with VB.NET or VB6?

十年热恋 提交于 2019-12-20 02:17:15

问题


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

I know how to do it through the command prompt but am trying to find some Visual Basic code to do it.

If it helps, this is the key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start


回答1:


Here's how'd you do 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'll need to make sure to add

Imports System
Imports Microsoft.Win32

at the top of your code.




回答2:


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

Download this registry editing code and put it into a class.

Then you can have code like the following to actually modify the value:

Dim reg As New RegistryClass

With reg
    .SetKeyValue .HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\USBSTOR", .RegDWORD, "Start", 4
End With



回答3:


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



来源:https://stackoverflow.com/questions/491890/how-can-i-edit-a-registry-key-with-vb-net-or-vb6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!