Its the first time I am trying to read keys / values from the registry and ended in a problem I was not able to solve. The following code runs ok under '98 SE but does not return keys and values under XP
The code above works, the code below doesn't
Can somebody guide me in the right direction or tell what's wrong? The first part (reading "ODBC.INI") works on both Windows versions, but the second (reading "ODBC Data Sources") on '98SE only.
rgds
Werner
regKey = "Software\ODBC\ODBC.INI"
lResult = REGOPENKEYEX( %HKEY_LOCAL_MACHINE, regKey, BYVAL 0&, %KEY_READ, hKey )
DO WHILE REGENUMKEYEX( hKey, isubkey, szKeyName, %MAX_PATH, dwReserved, szClass, %MAX_PATH, Lastwrite ) = %ERROR_SUCCESS
COMBOBOX ADD CBHNDL, %IDC_ODBCDB, szKeyName
INCR iSubKey
LOOP
COMBOBOX SELECT CBHNDL, %IDC_ODBCDB, 1
REGCLOSEKEY( hKey )
lResult = REGOPENKEYEX( %HKEY_LOCAL_MACHINE, regKey, BYVAL 0&, %KEY_READ, hKey )
DO WHILE REGENUMKEYEX( hKey, isubkey, szKeyName, %MAX_PATH, dwReserved, szClass, %MAX_PATH, Lastwrite ) = %ERROR_SUCCESS
COMBOBOX ADD CBHNDL, %IDC_ODBCDB, szKeyName
INCR iSubKey
LOOP
COMBOBOX SELECT CBHNDL, %IDC_ODBCDB, 1
REGCLOSEKEY( hKey )
regKey = "SOFTWARE\ODBC\ODBC.INI\" + sText
lResult = REGOPENKEYEX( %HKEY_LOCAL_MACHINE, regKey, BYVAL 0&, %KEY_ALL_ACCESS, hKey )
IF lResult = %ERROR_SUCCESS THEN
szClass= space$(%MAX_PATH)
szVALUE= space$(%MAX_PATH)
DO WHILE REGENUMVALUE( hKey, cnt, szClass, %MAX_PATH, dwReserved, %REG_NONE, szValue, %MAX_PATH ) = %ERROR_SUCCESS
REDIM PRESERVE regs( 1 TO cnt + 1 )
regs( cnt + 1 ) = USING$( "&=&", UCASE$( szClass ), szValue )
INCR cnt
LOOP
ELSE
? using$("Kann REGISTRY & nicht lesen!", regKey),%MB_ICONERROR, "Fehler"
EXIT FUNCTION
END IF
REGCLOSEKEY( hKey )
regKey = "SOFTWARE\ODBC\ODBC.INI\ODBC DATA SOURCES"
lResult = REGOPENKEYEX( %HKEY_LOCAL_MACHINE, regKey, BYVAL 0&, %KEY_ALL_ACCESS, hKey )
IF lResult = %ERROR_SUCCESS THEN
DO WHILE REGENUMVALUE( hKey, dcnt, szClass, %MAX_PATH, dwReserved, %REG_SZ, szValue, %MAX_PATH ) = %ERROR_SUCCESS
REDIM PRESERVE regs( 1 TO cnt + 1 )
regs( cnt + 1 ) = USING$( "&=&", szClass, szValue )
INCR cnt
INCR dcnt
LOOP
ELSE
? USING$( "Kann REGISTRY & nicht lesen!", regKey ), %MB_ICONERROR, "Fehler"
EXIT FUNCTION
END IF
IF dcnt=0 THEN EXIT FUNCTION
REGCLOSEKEY( hKey )
sDB = create_dbstring( regs( ), TRIM$( sText ))
SQL_ERRORCLEARALL
SQL_OPENDATABASE( 2, sDB, %PROMPT_TYPE_NOPROMPT )
IF SQL_ERRORPENDING THEN
SQL_MSGBOX SQL_ERRORQUICKALL+$CRLF+"DSN: "+sDB, %MSGBOX_OK
EXIT FUNCTION
END IF
TableCnt = SQL_TABLECOUNT( 2 )
COMBOBOX RESET CBHNDL, %IDC_DBTABLE
FOR cnt = 1 TO TableCnt
COMBOBOX ADD CBHNDL, %IDC_DBTABLE, SQL_TABLEINFOSTR( 2, cnt, %TABLE_NAME )
NEXT
SQL_CLOSEDATABASE( 2 )
END IF
lResult = REGOPENKEYEX( %HKEY_LOCAL_MACHINE, regKey, BYVAL 0&, %KEY_ALL_ACCESS, hKey )
IF lResult = %ERROR_SUCCESS THEN
szClass= space$(%MAX_PATH)
szVALUE= space$(%MAX_PATH)
DO WHILE REGENUMVALUE( hKey, cnt, szClass, %MAX_PATH, dwReserved, %REG_NONE, szValue, %MAX_PATH ) = %ERROR_SUCCESS
REDIM PRESERVE regs( 1 TO cnt + 1 )
regs( cnt + 1 ) = USING$( "&=&", UCASE$( szClass ), szValue )
INCR cnt
LOOP
ELSE
? using$("Kann REGISTRY & nicht lesen!", regKey),%MB_ICONERROR, "Fehler"
EXIT FUNCTION
END IF
REGCLOSEKEY( hKey )
regKey = "SOFTWARE\ODBC\ODBC.INI\ODBC DATA SOURCES"
lResult = REGOPENKEYEX( %HKEY_LOCAL_MACHINE, regKey, BYVAL 0&, %KEY_ALL_ACCESS, hKey )
IF lResult = %ERROR_SUCCESS THEN
DO WHILE REGENUMVALUE( hKey, dcnt, szClass, %MAX_PATH, dwReserved, %REG_SZ, szValue, %MAX_PATH ) = %ERROR_SUCCESS
REDIM PRESERVE regs( 1 TO cnt + 1 )
regs( cnt + 1 ) = USING$( "&=&", szClass, szValue )
INCR cnt
INCR dcnt
LOOP
ELSE
? USING$( "Kann REGISTRY & nicht lesen!", regKey ), %MB_ICONERROR, "Fehler"
EXIT FUNCTION
END IF
IF dcnt=0 THEN EXIT FUNCTION
REGCLOSEKEY( hKey )
sDB = create_dbstring( regs( ), TRIM$( sText ))
SQL_ERRORCLEARALL
SQL_OPENDATABASE( 2, sDB, %PROMPT_TYPE_NOPROMPT )
IF SQL_ERRORPENDING THEN
SQL_MSGBOX SQL_ERRORQUICKALL+$CRLF+"DSN: "+sDB, %MSGBOX_OK
EXIT FUNCTION
END IF
TableCnt = SQL_TABLECOUNT( 2 )
COMBOBOX RESET CBHNDL, %IDC_DBTABLE
FOR cnt = 1 TO TableCnt
COMBOBOX ADD CBHNDL, %IDC_DBTABLE, SQL_TABLEINFOSTR( 2, cnt, %TABLE_NAME )
NEXT
SQL_CLOSEDATABASE( 2 )
END IF
rgds
Werner
Comment