关于VB6修改注册表的问题
- 提问者网友:猖狂醉薇
- 2021-04-22 05:02
下面是一个声明
'写入注册表字符串键值
Public Sub SetString(hKey As Long, strPath As String, strValue As String, strdata As String)
Dim keyhand As Long
RegCreateKey hKey, strPath, keyhand
RegSetValueEx keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata)
RegCloseKey keyhand
End Sub
下面是一行代码,用来添加的
SetString HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "IE老板键", App.Path & "\IE老板键.exe"
结果添加是添加了,值也比较正常,只是后缀名没了。怎么回事?该怎么修改?
- 二级知识专家网友:晚安听书人
- 2021-04-22 06:19
【Len(strdata)】这个有问题。
- 1楼网友:萝莉姐姐鹿小北
- 2021-04-22 07:35
option explicit '--------------------------------------------------------------- '-注册表 api 声明... '--------------------------------------------------------------- private declare function regclosekey lib "advapi32" (byval hkey as long) as long private declare function regopenkeyex lib "advapi32" alias "regopenkeyexa" (byval hkey as long, byval lpsubkey as string, byval uloptions as long, byval samdesired as long, byref phkresult as long) as long private declare function regqueryvalueex lib "advapi32" alias "regqueryvalueexa" (byval hkey as long, byval lpvaluename as string, byval lpreserved as long, byref lptype as long, byval lpdata as string, byref lpcbdata as long) as long private declare function regsetvalueex lib "advapi32" alias "regsetvalueexa" (byval hkey as long, byval lpvaluename as string, byval reserved as long, byval dwtype as long, byval lpdata as string, byval cbdata as long) as long
'--------------------------------------------------------------- '- 注册表 api 常数... '--------------------------------------------------------------- ' reg data types... const reg_sz = 1 ' unicode空终结字符串 const reg_expand_sz = 2 ' unicode空终结字符串
' 注册表关键字安全选项... const read_control = &h20000 const key_query_value = &h1 const key_set_value = &h2 const key_create_sub_key = &h4 const key_enumerate_sub_keys = &h8 const key_notify = &h10 const key_create_link = &h20 const key_read = key_query_value + key_enumerate_sub_keys + key_notify + read_control const key_write = key_set_value + key_create_sub_key + read_control const key_execute = key_read const key_all_access = key_query_value + key_set_value + _ key_create_sub_key + key_enumerate_sub_keys + _ key_notify + key_create_link + read_control ' 注册表关键字根类型...
private const hkey_current_user = &h80000001
' 返回值... const error_none = 0 const error_badkey = 2 const error_access_denied = 8 const error_success = 0
'
public function getkeyvalue(keyroot as long, keyname as string, subkeyref as string) as string dim i as long ' 循环计数器 dim rc as long ' 返回代码 dim hkey as long ' 处理打开的注册表关键字 dim hdepth as long ' dim skeyval as string dim lkeyvaltype as long ' 注册表关键字数据类型 dim tmpval as string ' 注册表关键字的临时存储器 dim keyvalsize as long ' 注册表关键字变量尺寸
rc = regopenkeyex(keyroot, keyname, 0, key_all_access, hkey) ' 打开注册表关键字 if (rc <> error_success) then goto getkeyerror ' 处理错误... tmpval = string$(1024, 0) ' 分配变量空间 keyvalsize = 1024 ' 标记变量尺寸 '------------------------------------------------------------ ' 检索注册表关键字的值... '------------------------------------------------------------ rc = regqueryvalueex(hkey, subkeyref, 0, _ lkeyvaltype, tmpval, keyvalsize) ' 获得/创建关键字的值 if (rc <> error_success) then goto getkeyerror ' 错误处理 tmpval = left$(tmpval, instr(tmpval, chr(0)) - 1)
select case lkeyvaltype case reg_sz, reg_expand_sz skeyval = tmpval case else msgbox "不是 reg_sz 值 或 reg_expand_sz 值" goto getkeyerror end select getkeyvalue = skeyval rc = regclosekey(hkey) exit function ' getkeyerror: getkeyvalue = vbnullstring rc = regclosekey(hkey) end function
'
private sub command1_click()
'调用方法(只能获取reg_expand_ 和 sz reg_sz 两种值) text1.text = getkeyvalue(hkey_current_user, "software\soso", "wenwen")
' 这里是获取hkey_current_user\software\soso项下的wenwen的值 end sub