用VB5读写注册表实例,第1张

用VB5读写注册表实例,第2张

用VB5读写注册表实例

首先新建一个项目,在新创建的窗体上添加以下控件并设置相应的属性:
控件名称属性值
Label1 Caption注册表键值:
Label2 Caption注册名称:
label 3 Caption空
4 label Caption注册公司:
label 5 Caption空
label 6 Caption/[/K6 Caption 在程序的声明部分添加以下代码:
私有声明函数regcreate key lib "advapi32.dll "别名" regcreate key a" (Byval HKEY为long,Byval LP subkey为string,phkResult为Long)
私有声明函数RegQueryValueEx Lib " advapi32 . dll "别名" regqueryvaluexa "(Byval hKey为Long,ByVal lpValueName为String,ByVal lpReserved为Long,lpType为Long,lpData为 ByVal lpValueName为String,ByVal Reserved为Long,ByVal dwType为Long,lpData为Any,ByVal cbData为Long)Long
Const error _ success = 0 &
Const error _ bad db = 1009 &
Const error _ bad key = 1010 &
Const error _ cant open = 1011 &
Const error _ cantread = 1012 &
Const error _ cant myprogram"
然后为每个控件添加代码,代码如下:
private subcommand 1 _ click()
dim key value as string
dim ret value as long
dim key id as long
ret value = regcreatekey(hda 0 key _ local _ machine,regkey,keyid)
key value = text 1 . text
ret value = regsetvalueex(keyid,"注册名称",0& Reg _ SZ,by 文本“”和文本2。文本"",然后
标签3。标题=文本1。Text
Label5。标题=文本2。text
End If
End Sub

Private Sub command 2 _ Click()
Unload Me
End
End Sub

Private Sub Form _ Load()
Dim retvalue As Long
Dim key id As Long
Dim key value As String
Dim Sub subkey As String
Dim size As String
Dim bufsize Ascaption = regkey
retvalue = RegCreateKey(HKEY _ local _ machine,regkey,Key)
ifretvalue = 0 Then
subkey = "注册名称"
retvalue = RegQueryValueEx(keyid,subkey,0&,reg _ sz,0 & bufsize)
如果bufsize < 2,则
Key value = " "
retvalue = RegSetValueEx(keyid,subkey,0 &,REG_SZ buff-1)
text 1 . text = key value
end If
label 3 . caption = key value
subkey = "注册公司"
retvalue = RegQueryValueEx(keyid,subkey,0&,REG_SZ,0&,bufsize)
如果bufsize < 2,则
key value = " "
retvalue = RegSetValueEx(keyid,subkey,0&,REG_SZ,by text = key value
End If
label 5。caption = key value
End If
End Sub

好,保存它,按F5运行程序,用两个文本写下你的“注册名称”和“注册公司”的名称,然后点击

“写注册表”按钮,现在打开注册表编辑器,找到HKEY _ local _ machine \ software \ my soft \ my program,看看右边是否生成了“注册名称”和“注册公司”两个键值。如果是,那么恭喜你,你成功了。

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » 用VB5读写注册表实例

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情