Question RegSaveKey() : how to use this function?

ghafarifar

New member
Joined
Nov 7, 2009
Messages
2
Programming Experience
Beginner
Hello
RegSaveKey() & RegRestoreKey : how to use this function in vb.net?
any simple example?
 
I thought I'd have a go and I got as far as this:
VB.NET:
Imports System.Runtime.InteropServices

Public Class Form1

    Private Const KEY_ALL_ACCESS As Integer = &HF003F

    Private ReadOnly HKEY_LOCAL_MACHINE As New IntPtr(-2147483646)

    <DllImport("Advapi32")> _
    Private Shared Function RegOpenKeyEx(ByVal hKey As IntPtr, _
                                         ByVal lpSubKey As String, _
                                         ByVal ulOptions As Integer, _
                                         ByVal samDesired As Integer, _
                                         ByRef phkResult As IntPtr) As Long
    End Function

    <DllImport("Advapi32")> _
    Private Shared Function RegSaveKey(ByVal hKey As IntPtr, _
                                       ByVal lpFile As String, _
                                       ByVal lpSecurityAttributes As Integer) As Long
    End Function


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim key As IntPtr

            RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
                         "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", _
                         Nothing, _
                         KEY_ALL_ACCESS, _
                         key)
            RegSaveKey(key, _
                       IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, _
                                       "Run.reg"), _
                       Nothing)
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub

End Class
That doesn't work but it's 1.15 AM here so I'm not really prepared to investigate any further right now. That should give you something to work from at least. I'd suggest the first course of action would be to get the result from RegOpenKeyEx and see what the corresponding error message is.
 
Thanks, your answer
not working.
I was faced with a blank file
Is another way to get it export the registry sub key?
Any method.
 
your answer not working.
Yep, I did say that:
That doesn't work but it's 1.15 AM here so I'm not really prepared to investigate any further right now. That should give you something to work from at least.
Did you you make any attempt to determine why it's not working?
I'd suggest the first course of action would be to get the result from RegOpenKeyEx and see what the corresponding error message is.
 
Back
Top