I wanted to use in an agent a simple working VB code, but in LS it doesn’t work: when I try to open the registry with the function RegOpenKeyEx I get the error code 87 and neverenter the while loop. As said, it works perfectly in VB. Can someome help me ?
Many Thanks
Stefano
Declare Private Function RegCloseKey Lib “advapi32.dll” (Byval hKey As Long) As Long
Declare Private 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
Declare Private Function RegEnumKeyEx Lib “advapi32.dll” Alias “RegEnumKeyExA” (Byval hKey As Long, Byval dwIndex As Long, Byval lpName As String, lpcbName As Long, Byval lpReserved As Long, Byval lpClass As String, lpcbClass As Long, lpftLastWriteTime As Any) As Long
Declare Private 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
Const UninstallKey=“SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall”
Const HKEY_LOCAL_MACHINE = &H80000002
Const KEY_ENUMERATE_SUB_KEYS = &H8
Const KEY_QUERY_VALUE = &H1
Const ERROR_SUCCESS = 0&
Dim hKey As Long
Dim hSubKey As Long
Dim SubKey As String * 1000
Dim Index As Long
Dim pData As String * 1000
Dim lData As Long
RegOpenKeyEx HKEY_LOCAL_MACHINE, UninstallKey, 0, KEY_ENUMERATE_SUB_KEYS, hKey
’ <<<- HERE I GET ERROR CODE 87 AND NEVER
’ ENTER THE LOOP
While RegEnumKeyEx(hKey, Index, SubKey, Len(SubKey), 0, vbNullString, Byval 0&, Byval 0&) = ERROR_SUCCESS
lData = Len(pData)
RegOpenKeyEx HKEY_LOCAL_MACHINE, UninstallKey & "" & SubKey, 0, KEY_QUERY_VALUE, hSubKey
If RegQueryValueEx(hSubKey, “DisplayName”, 0, Byval 0, Byval pData, lData) = ERROR_SUCCESS Then
Msgbox pData
End If
RegCloseKey hSubKey
Index = Index + 1
Wend
RegCloseKey hKey