上饶铁路医院眼科:球VB操作注册表的代码?

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/19 13:13:49
比如我将HLM\software\microsoft\windows下名叫test的Dword值由3变为5,应该如何写VB的代码?

谢谢

成功后加分!

Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long

Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_DWORD = 4

Private Sub Command1_Click()
'写注册表
Dim Ret2 As Long
Dim llll As Long
Dim str As String
llll = Len(str) + 1
'打开 HKEY_LOCAL_MACHINE 下的 software\microsoft\windows\test 主键
RegCreateKey HKEY_LOCAL_MACHINE, "software\microsoft\windows\test", Ret2
'将此主键下的“默认”项的值改为"c:\windows\system\myprogram.exe",也就是要开机运行的程序路径
RegSetValueEx Ret2, "fender", 0, REG_DWORD, ByVal "&H5", 255
'关闭对主键的操作
RegCloseKey Ret2
End Sub