Accessing win registry: same code working in VB, not in LS

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

Subject: Accessing win registry: same code working in VB, not in LS

OK, I should have paid more attention to the enumerate keys part of your post. I believe this requires a callback function and I suspect is not do-able directly or completely in LotusScript. C and VB have good support for writing callback functions and passing the address of those functions as arguments. I have only been able to read and write to keys, not enumerate them.

Stephen

Subject: RE: Accessing win registry: same code working in VB, not in LS

Hi Stephen,my problem is when calling the

function “RegEnumKeyEx” (to collect multiple subkeys against one key). I thank you for

your post, but I couldn’t find this function

in the code you posted.

I’ve searched both R5 and R6 forum: in the

R5 forum other people found that there is an issue when calling this specific function

from LS (while it works perfectly in VB)

but I didn’t find an answer to this problem.

My idea is that as the same code works in VB

and not in LS perhaps there could be a problem

when casting the parameters to pass to the

“RegEnumKeyEx” and that in LS this parameters

must be cast in a different way. But I do not

know how to workaround this problem.

Thank you

Stefano

Subject: Accessing win registry: same code working in VB, not in LS

Hello,

i would add KEY_QUERY_VALUE to the flags:

Const KEY_QUERY_VALUE = &H1

Dim lFlags as Long

lFlags = KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS

RegOpenKeyEx HKEY_LOCAL_MACHINE, UninstallKey, 0, lFlags, hKey

Dunno if this helps, but it’s worth trying…

Kuwe