永发信息网

怎么用VB读取注册表数值?

答案:2  悬赏:0  手机版
解决时间 2021-04-13 07:17

怎么用VB读取注册表的数值?结果显示在 Text1 Text2 Text3里?以下是路径。

HKEY_USERS/S-1-5-21-1085031214-1004336348-725345543-500/Software/sicent/wx2004Clt/ 下的“!!!RunSetCipher”、“!!!UnlockCipher”、“!!!IESetCipher” 的数值

本人是菜鸟,所以请写详细些,谢谢!

谢谢!

最佳答案

下边是个实例,我测试过,绝对好使


复制代码即可运行,加以个LABLE,一个按钮


Option Explicit


Const REG_SZ As Long = 1
Const REG_DWORD As Long = 4
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const ERROR_NONE = 0
Const ERROR_BADDB = 1
Const ERROR_BADKEY = 2
Const ERROR_CANTOPEN = 3
Const ERROR_CANTREAD = 4
Const ERROR_CANTWRITE = 5
Const ERROR_OUTOFMEMORY = 6
Const ERROR_INVALID_PARAMETER = 7
Const ERROR_ACCESS_DENIED = 8
Const ERROR_INVALID_PARAMETERS = 87
Const ERROR_NO_MORE_ITEMS = 259
Const KEY_ALL_ACCESS = &H3F
Const REG_OPTION_NON_VOLATILE = 0
Const SPI_SETDESKWALLPAPER = 20
Const SPIF_SENDWININICHANGE = &H2
Const SPIF_UPDATEINIFILE = &H1


Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long) As Long
Private Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long) As Long
Private Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
Private Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, ByVal cbData As Long) As Long
Private Declare Function RegDeleteKey& Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String)
Private Declare Function RegDeleteValue& Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String)


'读取键值
Private Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As String, vValue As Variant) As Long
Dim cch As Long
Dim lrc As Long
Dim lType As Long
Dim lValue As Long
Dim sValue As String


On Error GoTo QueryValueExError


lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
If lrc <> ERROR_NONE Then Error 5


Select Case lType
Case REG_SZ:
sValue = String(cch, 0)
lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, sValue, cch)
If lrc = ERROR_NONE Then
vValue = Left$(sValue, cch)
Else
vValue = Empty
End If


Case REG_DWORD:
lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, lValue, cch)
If lrc = ERROR_NONE Then vValue = lValue
Case Else
lrc = -1
End Select


QueryValueExExit:


QueryValueEx = lrc
Exit Function


QueryValueExError:


Resume QueryValueExExit


End Function
Private Function QueryValue(lPredefinedKey As Long, sKeyName As String, sValueName As String)
Dim lRetVal As Long
Dim hKey As Long
Dim vValue As Variant


lRetVal = RegOpenKeyEx(lPredefinedKey, sKeyName, 0, KEY_ALL_ACCESS, hKey)
lRetVal = QueryValueEx(hKey, sValueName, vValue)
QueryValue = vValue
RegCloseKey (hKey)
End Function


Private Sub Command1_Click()
Label1.Caption = QueryValue(HKEY_LOCAL_MACHINE, "SOFTWARE\Tencent\QQ", "Install")
End Sub

全部回答
Private Sub Form_Load() Set w = CreateObject("wscript.shell") Text1.Text = w.regread("HKEY_USERS/S-1-5-21-1085031214-1004336348-725345543-500/Software/sicent/wx2004Clt/RunSetCipher ") End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
运管局的执法人员,跑黑车是不是违法,
小学生玩游戏老喜欢说话怎么办
爱好旅游下一句是什么,第一句:在每个夜深人
骆驼祥子每章归纳【要一章一章地详细说】
She a smile when she heard her family wen
树上的小鸟不鸟不停地啼叫改成拟人句
广东陶瓷地址在什么地方,想过去办事
大学读室内装潢要多少年才可拿到学士证书?
人的大脑为什么有记忆和理解的能力?
今天在展会上看到帅康cxw-200-t868s,风量17
和田玉怎么保养,和田玉的英文名称是什么
多选题下列既体现唯物辩证法联系的观点,又体
传奇世界玩什么角色好
使命召唤ol可以开出永久马格南吗
QQ宠物狗体力完了怎么办?
推荐资讯
关于伊丽莎白的电影,到底几集啊?
诺基亚可上QQ的手机最便宜的多少钱?
阿房宫赋中的名言,中英句子对译
在手机QQ空间怎么弄幻灯片
单选题下列关于组成细胞的元素和化合物的叙述
梦见人死了,梦见好多蚕,生吃蚕
当你在和他/她交往的时候,什么时候才是最幸
检修车间5S现场管理看板内容包括那些吗 详细?
苏后桥在哪里啊,我有事要去这个地方
阿甘正传电影英文台词,跪求白雪公主之魔镜魔
最伟大的魔术师是谁啊?
亚洲有哪些明星(非导演)获得奥斯卡和格莱美
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?