Results 1 to 13 of 13

Thread: [RESOLVED] read REG_NONE IconUnderline value

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Resolved [RESOLVED] read REG_NONE IconUnderline value

    Hello,

    i'am trying to read the value IconUnderline which exist on that path

    Code:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\IconUnderline
    i never worked beforewith REG_NONE

    Thanks
    Last edited by killer7k; Jul 26th, 2009 at 08:04 AM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: read REG_NONE IconUnderline value

    check the key, shows with the type he says
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: read REG_NONE IconUnderline value

    Thank you for reporting this issue with the RegistryKey.GetValue method.

    Unfortunately GetValue does not support reading values of type REG_NONE or REG_LINK at this time. We will consider adding this support for version 3 of the .NET Framework.

    Thanks,
    Josh Free
    from http://connect.microsoft.com/VisualS...edbackID=97603
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: read REG_NONE IconUnderline value

    A REG_NONE is merely a string represented in hex. Read it just as you would a REG_SZ string without a null terminating character. You need to use the registry APIs to do this, as it is not supported by WSH or WMI.

    In NET, you read it into a byte array (with GetValue) then optionally use BitConverter to convert it to a string.
    Last edited by schoolbusdriver; Jul 26th, 2009 at 03:20 AM. Reason: Clarification

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: read REG_NONE IconUnderline value

    can you some help with a sample
    basic code reading registry dont work with the case REG_NONE
    it show blank only

    Thanks

  6. #6
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: read REG_NONE IconUnderline value

    Post the code that you have already and we can go through it to show you where you need to make changes.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: read REG_NONE IconUnderline value

    Hi i use this code for reading but show blank

    Code:
    Private Function Registry_Read(Key_Path, Key_Name) As Variant
    
        On Error Resume Next
    
        Dim Registry As Object
    
        Set Registry = CreateObject("WScript.Shell")
    
        Registry_Read = Registry.RegRead(Key_Path & Key_Name)
    
    End Function
    
    Private Sub Form_Load()
    
    MsgBox Registry_Read("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\", "IconUnderline")
    
    End Sub

  8. #8
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: read REG_NONE IconUnderline value

    Use this instead. A REG_NONE can contain anything, so the data type you specify for lpData in RegQueryValueEx determines the outcome. In this case IconUnderline appears to be a number. The following example can provide either a hex string or a number.

    vb Code:
    1. 'Form level code.
    2.  
    3. Option Explicit
    4.  
    5. Private Sub Form_Load()
    6.    
    7.    Const HKEY_LOCAL_MACHINE = &H80000002
    8.    Const SUBKEY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer"
    9.    Const VALUE_NAME = "IconUnderline"
    10.  
    11.    MsgBox RegReadNoneString(HKEY_LOCAL_MACHINE, SUBKEY, VALUE_NAME)
    12. End Sub

    vb Code:
    1. 'Module level code.
    2.  
    3. Option Explicit
    4.  
    5. Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
    6.    (ByVal Hkey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
    7.    ByVal samDesired As Long, ByRef phkResult As Long) As Long
    8.  
    9. Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
    10.    (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, _
    11.    ByRef lpType As Long, ByRef lpData As Any, ByRef lpcbData As Long) As Long
    12.  
    13. Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
    14.  
    15. Public Const REG_OPTION_RESERVED = 0&
    16. Public Const KEY_QUERY_VALUE = &H1
    17. Public Const ERROR_SUCCESS = 0&
    18. Public Const ERROR_MORE_DATA = 234
    19. Public Const REG_NONE = 0
    20.  
    21. Public Function RegReadNoneString(lngHKey As Long, strSubKey As String, strValueName As String) As String
    22.    Dim lngErrVal     As Long
    23.    Dim lngKeyHandle  As Long
    24.    Dim lngDataType   As Long
    25.    Dim lngDataSize   As Long
    26.    Dim intIndex      As Integer
    27.    Dim bytRetVal()   As Byte
    28.    Dim strRetVal     As String
    29.    Dim lngRetVal     As Long
    30.  
    31. 'Open the new key.
    32.    lngErrVal = RegOpenKeyEx(lngHKey, strSubKey, REG_OPTION_RESERVED, KEY_QUERY_VALUE, lngKeyHandle)
    33.    If lngErrVal = ERROR_SUCCESS Then
    34. 'Get the key`s data length. It should return ERROR_MORE_DATA.
    35.       lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, lngDataType, 0&, lngDataSize)
    36. 'Size the data array.
    37.       ReDim bytRetVal(lngDataSize)
    38.       If lngErrVal = ERROR_MORE_DATA Then
    39. 'Test for REG_NONE.
    40.          If lngDataType = REG_NONE Then
    41. 'Get the current value.
    42.             lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, bytRetVal(0), lngDataSize)
    43.          End If
    44. ''////////////////////////////////////////////////
    45. ''Format the data into a binary string.
    46.          For intIndex = 0 To lngDataSize - 1
    47.             strRetVal = strRetVal & Right("00" & bytRetVal(intIndex), 2) & " "
    48.          Next
    49.          strRetVal = Left$(strRetVal, Len(strRetVal) - 1)
    50.          RegReadNoneString = strRetVal
    51. ''////////////////////////////////////////////////
    52. ''Alternative for a LONG.
    53. '         lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, lngRetVal, lngDataSize)
    54. '         RegReadNoneString = CStr(lngRetVal)
    55. ''////////////////////////////////////////////////
    56.       End If
    57.    End If
    58. 'Close any key opened with RegOpenKeyEx.
    59.    Call RegCloseKey(lngKeyHandle)
    60. End Function

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: read REG_NONE IconUnderline value

    Hi schoolbusdriver ,

    Thanks for your sample but seem that dont work with other
    i tested with IconUnderline is fine it return the true value

    but when i tested with others it show wrong value
    how can that happen ?

    here you how it look like



    Thanks

  10. #10
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: read REG_NONE IconUnderline value

    Quote Originally Posted by schoolbusdriver View Post

    A REG_NONE can contain anything, so the data type you specify for lpData in RegQueryValueEx determines the outcome.
    Unlike other data types, the data in a REG_NONE is undefined, so it is up to YOU to interpret the data. The "wrong" data you're showing is actually the decimal value of the hex data....

    As it is 5 bytes long it is probably a string - the last "00" being a null, so instead of using

    Code:
    lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, bytRetVal(0), lngDataSize)
    or

    Code:
    lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, lngRetVal, lngDataSize)
    try

    Code:
    lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, strRetVal, lngDataSize)
    Bear in mind that the data may also be mix of data types that are supposed to be put into a UDT - so unless you know the structure of the UDT it may not be decipherable.

    If it's not a value that you have written, count the bytes.......

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: read REG_NONE IconUnderline value

    Hi ,

    When you added it crash application

    Code:
    lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, strRetVal, lngDataSize)
    unless there is a way of this crash to be fixed i will use the byte
    Code:
    lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, bytRetVal(0), lngDataSize)
    and convert it from Dec2Hex even sometimes it got more than 5 byte..

    do you have any tips or good idea schoolbusdriver ?

    Thanks
    Last edited by killer7k; Jul 27th, 2009 at 02:38 PM.

  12. #12
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: read REG_NONE IconUnderline value

    My bad, it should have been "ByVal strRetVal" i.e.

    vb Code:
    1. Public Function RegReadNoneString(lngHKey As Long, strSubKey As String, strValueName As String) As String
    2.    Dim lngErrVal     As Long
    3.    Dim lngKeyHandle  As Long
    4.    Dim lngDataType   As Long
    5.    Dim lngDataSize   As Long
    6.    Dim strRetVal     As String
    7.  
    8. 'Open the new key.
    9.    lngErrVal = RegOpenKeyEx(lngHKey, strSubKey, REG_OPTION_RESERVED, KEY_QUERY_VALUE, lngKeyHandle)
    10.    If lngErrVal = ERROR_SUCCESS Then
    11. 'Get the key`s data length. It should return ERROR_MORE_DATA.
    12.       lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, lngDataType, 0&, lngDataSize)
    13.       If lngErrVal = ERROR_MORE_DATA Then
    14. 'Test for REG_NONE.
    15.          If lngDataType = REG_NONE Then
    16. 'Size the string.
    17.             strRetVal = Space$(lngDataSize)
    18. 'Get the current value.
    19.             lngErrVal = RegQueryValueEx(lngKeyHandle, strValueName, REG_OPTION_RESERVED, 0&, ByVal strRetVal, lngDataSize)
    20.             RegReadNoneString = strRetVal
    21.          End If
    22.       End If
    23.    End If
    24. 'Close any key opened with RegOpenKeyEx.
    25.    Call RegCloseKey(lngKeyHandle)
    26. End Function

    How you convert it depends on what you want to display.

    If you are confident handling the registry you could try the following.

    Create a plain text file containing:

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer]
    "Test"=hex(0):3e,3d,3c,3a,00
    Rename it to "test.reg" and double click on it and merge it with the registry. This will put the binary data you mentioned into the same subkey that contains "IconUnderline".

    Use the code in this post to read the value "Test". The message box will display the ascii string:- >=<:

    Don't forget to delete it when you've done.

    With a REG_NONE it's a case of "what do you want to do". Because it's undefined you could, for example, use it to store an encrypted gif of a password

    Any other tips will cost you lots of hard cash
    Last edited by schoolbusdriver; Jul 28th, 2009 at 11:33 AM.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: read REG_NONE IconUnderline value

    Hi,

    your last update didnt work show blank

    so i think i will stay on Dec2hex way work for now

    i really appreciate your help schoolbusdriver

    cheerz & Thanks
    Last edited by killer7k; Jul 27th, 2009 at 07:07 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width