★ 第3遍问这个问题了. 关于VB操作注册表的问题.请高手相助!!!

yunok 2003-05-11 09:04:06
问题1:
我想改变 HKEY_CLASSES_ROOT下的 * 这个子项的值,系统默认的名称为"默认",值为" " (或者值为“未设键值”),我用
Call RegSetValueEx(hKey, "(默认)", 0, REG_SZ, ByVal "abcd", 26) 后,发现在*的子项下 又建立了一个 名称为(默认) ,值为abcd的值. 请问如何改变(系统不允许删除这个"默认"名称) 这个系统自动建立的"(默认)"?? (注:'RegDeleteValue hKey, "(默认)" 也是不行的。只能删除自己建立的值。却不能删除系统建立的。 )

(注:请各位看清楚了,我要改变的是"(默认)"这个名称,就是改变默认这两个字,而不是改变他的数据,好多人告诉我的都是改变"(默认)"的数据,不符合要求啊!! )




问题2:

请各位高手将以下代码复制到窗体中试试,然后在 HKEY_CURRENT_USER\AppEvents会发现一个名称是File的值.

以下代码当L=1的时候,名称为File的键值为1,当L=0 的时候却不起任何作用。请问是为什么?我的目的是,如何才能让File的值显示为0x00000000 (0).(当值为0的时候就会显示的) (当然手工修改注册表可以正确实现的.)

Option Explicit
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
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 RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Const HKEY_CURRENT_USER = &H80000001
Const REG_SZ = 1& '字符串值
'Const REG_BINARY = 3& '二进制值
Const REG_DWORD = 4& 'DWORD 值
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




Private Sub Command1_Click()
Dim ret As Long, hKey As Long

ret = RegCreateKey(HKEY_CURRENT_USER, "AppEvents", hKey)

Dim L As Long
L = 1
Call RegSetValueEx(hKey, "File", 0, REG_DWORD, L, 4)
RegCloseKey hKey

End Sub

...全文
7 点赞 收藏 31
写回复
31 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yunok 2003-05-12
啊!!!谢谢.我太笨了.我会努力的!!非常感谢.
回复
verybelial 2003-05-12
Option Explicit
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
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 RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Const HKEY_CURRENT_USER = &H80000001
Const REG_SZ = 1& '字符串值
'Const REG_BINARY = 3& '二进制值
Const REG_DWORD = 4& 'DWORD 值
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




Private Sub Command1_Click()
Dim ret As Long, hKey As Long

ret = RegCreateKey(HKEY_CURRENT_USER, "AppEvents", hKey)

Dim L As Long
L = 0
Call RegSetValueEx(hKey, "File", 0, REG_DWORD, L, Len(L))
RegCloseKey hKey

End Sub

很简单啊,嘻嘻
回复
yunok 2003-05-12
是吗??请告诉我啊!!!非常感谢呀!
回复
verybelial 2003-05-12
你的问题以解决了。 嘻嘻
回复
yunok 2003-05-11
我要去睡觉了.要是那位朋友写出来了第2个问题的答案.麻烦您用QQ或者致信到 supervb@163.com 告知解决方法.感激不尽!!另开贴高分相送也可.
回复
yunok 2003-05-11
To: verybelial(顶级狙击手)
OK,非常感谢
回复
yunok 2003-05-11
To: verybelial(顶级狙击手)
用2进制也不行.晕死~
回复
verybelial 2003-05-11
有事,下次在QQ上给答案给你。
回复
yunok 2003-05-11
第一个问题已经被verybelial(顶级狙击手) 解决了,请各位朋友帮助解决第2个问题就行了.非常感谢.
My QQ:9227066 Tel:0411-2113485 我是辽宁大连的.
MY Name: 杨云鹏
回复
yunok 2003-05-11
To: verybelial(顶级狙击手)
OK,期待高手的解答.
回复
yunok 2003-05-11
To: Rozre(神灵)
没来晚.还有第2个问题没有解决呢.解决了我在开贴给你分.
回复
verybelial 2003-05-11
不用结帐那么快,等我回答再给吧。
回复
Rozre 2003-05-11
来晚了
回复
yunok 2003-05-11
好.立即结帐.
请问第2个问题您能回答吗? (不能回答也给分的.)
回复
verybelial 2003-05-11
第二个问题用二进制试一下,看行不?
回复
verybelial 2003-05-11
给分吧,哈哈哈
回复
yunok 2003-05-11
To : verybelial(顶级狙击手) :
太好了!!!!!!!这一句Call RegSetValueEx(hKey, "", 0, REG_DWORD,byval L, 4).解决了问题!!!非常感谢你啊狙击手,我真是太粗心了. 真的非常感谢你!!!
回复
verybelial 2003-05-11
试这句啊Call RegSetValueEx(hKey, "", 0, REG_SZ, ByVal "abcd", 4)
回复
yunok 2003-05-11
To : verybelial(顶级狙击手)
容我试一下这一句 Call RegSetValueEx(hKey, "", 0, REG_DWORD,byval L, 4).非常感谢.
回复
verybelial 2003-05-11
试一下啊
Call RegSetValueEx(hKey, "", 0, REG_SZ, ByVal "abcd", 4)
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告