locked
Registry read and enumerate values. RRS feed

  • Question

  • Hello,

    As the tittle says I want to read something from the registry.
    I want to read the IE credentials stored in the registry. I know the path is this :HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IntelliForms\Storage2

    but I have no idea how to read it in C#.

    Anyone have any idea?

    Edit: I tried this but it print out nothing:

    string

    text = Registry.GetValue(@"Software\Microsoft\Internet Explorer\IntelliForms\Storage2", "", "").ToString();


    • Edited by ileandros Friday, January 2, 2015 12:23 AM
    Friday, January 2, 2015 12:01 AM

All replies

  • Hello,

    As the tittle says I want to read something from the registry.
    I want to read the IE credentials stored in the registry. I know the path is this :HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IntelliForms\Storage2

    but I have no idea how to read it in C#.

    Anyone have any idea?

    How about something like:

     
    string reg = Registry.GetValue (@"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IntelliForms", "Storage2", "") as string;


    assuming that Storage2 is of type REG_SZ. You can change it to whatever is appropriate on your system.

    Friday, January 2, 2015 12:23 AM
  • Also  check your Data whether it is null.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, January 2, 2015 9:07 AM
  • Hello,

    As the tittle says I want to read something from the registry.
    I want to read the IE credentials stored in the registry. I know the path is this :HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IntelliForms\Storage2

    but I have no idea how to read it in C#.

    Anyone have any idea?

    How about something like:

     
    string reg = Registry.GetValue (@"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IntelliForms", "Storage2", "") as string;


    assuming that Storage2 is of type REG_SZ. You can change it to whatever is appropriate on your system.

    That is what I tried but it returns nothing.
    I have to enumerate through the keys since we don't know them yet and then read the registry.
    RegEnumValue is the function according to the msdn but I don't know the correct way in c#.
    Friday, January 2, 2015 12:52 PM
  • I'm not convinced your reg key is correct. On my version of IE no such subkey exists but it still remembers my credentials.  Additionally in your sample code you are not specifying the root key. 

    Irrelevant to enumerate child keys you use GetSubKeyNames.  Note that secure data like credentials are generally stored as binary, not string so use RegEdit to confirm the type of the values you're trying to read.

    static void Main (string[] args)
    {
        using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Intelliforms", false))
        {
            foreach (var child in key.GetSubKeyNames())
            {
                using (var childKey = key.OpenSubKey(child))
                {
                    //Do whatever
                };
            };
        };
    }

    Michael Taylor
    http://blogs.msmvps.com/p3net

    Friday, January 2, 2015 3:55 PM
  • I'm on IE11 and the path is that. Actually the path is the same from version 7-8 and after.
    And I am sure because I have already done this with the programming language I use.
    Here is a small reproducer, it will be easy to understand

    Local $sVar = ""
    Local $sPath = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IntelliForms\Storage2"
    Local $Credentials
    For $i = 1 To 1000
     $sVar = RegEnumVal($sPath, $i)
     If @error <> 0 Then ExitLoop
     $Credentials = RegRead($sPath, $sVar)
     ConsoleWrite("Value Name  #" & $i & ": " &  $sVar & @LF)
     ConsoleWrite("Encrypted credential: " & $Credentials & @CRLF & @CRLF)
    Next


    It is in autoit and I am trying to translate this to c#

    An other more complicated example is this:

    #include <APIRegConstants.au3>
    #include <Array.au3>
    #include <WinAPIDiag.au3>
    #include <WinAPIReg.au3>
    
    Global $gsValName, $giType
    Global $giCount = 0
    Global $gaInfo[101][3]
    
    Global $ghKey = _WinAPI_RegOpenKey($HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\IntelliForms\Storage2", $KEY_READ)
    ConsoleWrite($ghKey & @LF)
    While 1
        $gsValName = _WinAPI_RegEnumValue($ghKey, $giCount)
        If @error Then ExitLoop
        $giType = @extended
        If Mod($giCount, 100) = 0 Then
            ReDim $gaInfo[$giCount + 100][3]
        EndIf
        $gaInfo[$giCount][0] = $gsValName
        $gaInfo[$giCount][1] = $giType
        $gaInfo[$giCount][2] = RegRead("HKCU\Software\Microsoft\Internet Explorer\IntelliForms\Storage2", $gsValName)
        $giCount += 1
    WEnd
    _WinAPI_RegCloseKey($ghKey)
    ReDim $gaInfo[$giCount][3]
    _ArrayDisplay($gaInfo)

    However since c# doesn't support Redim I didn't want to post it.

    • Edited by ileandros Friday, January 2, 2015 7:48 PM
    Friday, January 2, 2015 7:46 PM
  • So anyone who has any better ideas?
    Monday, January 5, 2015 12:38 PM
  • I'm on IE11 and the path is that. Actually the path is the same from version 7-8 and after.
    And I am sure because I have already done this with the programming language I use.
    Here is a small reproducer, it will be easy to understand

    Local $sVar = ""
    Local $sPath = "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\IntelliForms\Storage2"
    Local $Credentials
    For $i = 1 To 1000
     $sVar = RegEnumVal($sPath, $i)
     If @error <> 0 Then ExitLoop
     $Credentials = RegRead($sPath, $sVar)
     ConsoleWrite("Value Name  #" & $i & ": " &  $sVar & @LF)
     ConsoleWrite("Encrypted credential: " & $Credentials & @CRLF & @CRLF)
    Next


    It is in autoit and I am trying to translate this to c#

    An other more complicated example is this:

    #include <APIRegConstants.au3>
    #include <Array.au3>
    #include <WinAPIDiag.au3>
    #include <WinAPIReg.au3>
    
    Global $gsValName, $giType
    Global $giCount = 0
    Global $gaInfo[101][3]
    
    Global $ghKey = _WinAPI_RegOpenKey($HKEY_CURRENT_USER, "Software\Microsoft\Internet Explorer\IntelliForms\Storage2", $KEY_READ)
    ConsoleWrite($ghKey & @LF)
    While 1
        $gsValName = _WinAPI_RegEnumValue($ghKey, $giCount)
        If @error Then ExitLoop
        $giType = @extended
        If Mod($giCount, 100) = 0 Then
            ReDim $gaInfo[$giCount + 100][3]
        EndIf
        $gaInfo[$giCount][0] = $gsValName
        $gaInfo[$giCount][1] = $giType
        $gaInfo[$giCount][2] = RegRead("HKCU\Software\Microsoft\Internet Explorer\IntelliForms\Storage2", $gsValName)
        $giCount += 1
    WEnd
    _WinAPI_RegCloseKey($ghKey)
    ReDim $gaInfo[$giCount][3]
    _ArrayDisplay($gaInfo)

    However since c# doesn't support Redim I didn't want to post it.


    Hi ileandros

    From your code,  this is not C# code,  I am afraid this is out of our support. To read the IE credentials stored in the registry. Using CoolDadTx and Brian Muth code is ok. And in IE11 there is no such subkey exists in my machine.

    Best wishes!

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, January 13, 2015 8:04 AM