Share via

Minor Help

Peter Volz 1,295 Reputation points
2023-09-09T12:11:55.29+00:00

Hello

Having problem converting this code to vb.net:

https://learn.microsoft.com/en-us/answers/questions/1210974/backup-registry-key-values

Does not work, empty file is saved, any idea where's the problem? :(

        ' Check if the registry key exists
        Dim regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\company\appname")
        If regKey Is Nothing Then
            MsgBox("Registry key does not exist")
            Return
        End If
        ' Backup registry keys to text file
        Using writer As StreamWriter = New StreamWriter("d:\backup.txt")
            Dim valueNames As String() = regKey.GetValueNames()
            For Each valueName In valueNames
                If Equals(valueName, "") Then
                    Dim value As String = regKey.GetValue(valueName).ToString()
                    writer.WriteLine([String].Format("{0}={1}", valueName, value))
                    'writer.WriteLine("{valueName}={value}")
                End If
            Next
        End Using
Developer technologies | VB
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author

Viorel 127K Reputation points
2023-09-09T15:31:30.9566667+00:00

Try to use If valueName <> "" instead of If Equals(valueName, "").

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.