VB从注册表读取QQ完整安装路径:
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
'返回值: =0,表示成功;≠0,表示失败。[注意这一点与别的API函数不太一样]
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Function GetQQPath() As String
'使用regedit可以查到QQ的位置:HKEY_LOCAL_MACHINE\SOFTWARE\Tencent\QQ
'键install中的字符串就是安装路径
Dim ret, lenData, hKey As Long, sValue As String, name As String
sValue = Space(255)
Const REG_SZ = 1& '字符串值
lenData = 255
name = "Install" '在注册表查到的
ret = 1
ret = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Tencent\QQ", hKey)
If ret = 0 Then '正确返回0,不正确返回错误编号
ret = RegQueryValueEx(hKey, name, 0, REG_SZ, ByVal sValue, lenData) '注意ByVal千万别忘了
GetQQPath = sValue
End If
ret = RegCloseKey(hKey)
End Function
Private Sub Form_Load()
MsgBox GetQQPath()
End Sub |