vb查找注册表键值

Option Explicit

Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByRef lpData As Any, ByRef lpcbData As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, ByRef phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Const HKEY_LOCAL_MACHINE As Long = &H80000002

part1

STM32 Virtual COM Port所在的注册表地址。

注:STM32 Virtual COM Port的地址是不会因为USB拔插而消失,是一直存在的地址。

Private Sub Command3_Click()
Dim hKey As Long, ret As Long, Name As String, Idx As Long
Dim tempName As String
 
Name = String(256, Chr(0))
ret = RegOpenKey(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Enum\USB\Vid_0483&Pid_5740\Demo_1.000", hKey) '引号内容为目标注册表地址
If ret = 0 Then
    ret = RegQueryValueEx(hKey, "DeviceDesc", 0, 1, ByVal Name, Len(Name))
    RegCloseKey hKey
    MsgBox Name
Else
    MsgBox "没有这个项"
End If
Text1.Text = Name
Combo1.Text = Name'这里可以让COMBO显示STM32
End Sub
'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\Vid_0483&Pid_5740\Demo_1.000

PART2

COM口所在的地址。

注:会因为USB拔插而消失/存在。

Private Sub Command4_Click()
Dim hKey As Long, ret As Long, Name As String, Idx As Long
Dim tempName As String
 
Name = String(256, Chr(0))
ret = RegOpenKey(HKEY_LOCAL_MACHINE, "HARDWARE\DEVICEMAP\SERIALCOMM", hKey)
If ret = 0 Then
    ret = RegQueryValueEx(hKey, "\Device\USBSER000", 0, 1, ByVal Name, Len(Name))
    RegCloseKey hKey
    MsgBox Name
Else
    MsgBox "没有这个项"
End If
Combo1.Text = Name <span style="font-family: Arial, Helvetica, sans-serif;">'这里可以让COMBO显示COM</span>

End Sub


  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

qvttter

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值