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