Announcement

Collapse
No announcement yet.

Reading from Registry

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Kev Peel
    replied
    KEY_ALL_ACCESS
    You should only use KEY_READ when reading a registry value. Requesting write access will fail in some situations where the appropriate permissions have not been granted, such as in a "limited" user account.

    Leave a comment:


  • Knuth Konrad
    replied
    Try putting source code in [ code ] tags (without the space), not in [ quote ] tags. Code tags use a fixed width font and preserve code formating (indention).

    Leave a comment:


  • Werner Bleckwendt
    replied
    Found the reason:

    correct code is
    REGENUMVALUE( hKey, dcnt, szClass, %MAX_PATH, BYVAL 0&, BYVAL 0&, szValue, %MAX_PATH)
    rgds
    Werner
    Last edited by Werner Bleckwendt; 18 Apr 2008, 05:17 AM. Reason: Typing error

    Leave a comment:


  • Werner Bleckwendt
    started a topic Reading from Registry

    Reading from Registry

    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

    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 )
    The code above works, the code below doesn't

    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
    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
    Last edited by Werner Bleckwendt; 18 Apr 2008, 01:44 AM.
Working...
X