'Open New Project and add a module on it. Write down the public functions on the module.
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Public Const EWX_FORCE = 4
Public Const EWX_REBOOT = 2
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const REG_SZ = 1 ' Unicode nul terminated string
Public Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Public Const KEY_WRITE = &H20006



'Put two buttons and one commond dialog component on the form.
Private Sub Command1_Click()
Dim HRegKey As Long
Dim SecAttr As SECURITY_ATTRIBUTES
Dim SubKey As String
Dim neworused As Long
Dim StringBuffer As String
Dim RetVal As Long
With CommonDialog1
.Filter = "Executable Files (*.Exe)|*.Exe"
.DialogTitle = "Select Exe file"
.ShowSave
If Not .FileName = "" Then
SubKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
SecAttr.nLength = Len(SecAttr)
SecAttr.lpSecurityDescriptor = 0
SecAttr.bInheritHandle = True
RetVal = RegCreateKeyEx(HKEY_LOCAL_MACHINE, SubKey, 0, "", 0, KEY_WRITE, SecAttr, HRegKey, neworused)
If RetVal <> 0 Then
MsgBox "Error Opening or Creating Registry Key" & "Aborting", , "Warning"
End
End If
StringBuffer = .FileName & vbNullChar
RetVal = RegSetValueEx(HRegKey, "Testing", 0, REG_SZ, ByVal StringBuffer, Len(StringBuffer))
RetVal = RegCloseKey(HRegKey)
MsgBox "Now Restarting The Computer To See The Result..", vbOK, "Warning"
t& = ExitWindowsEx(EWX_REBOOT Or EWX_FORCE, 0)
End If
End With
End Sub

Private Sub Command2_Click()
Dim RetVal As Long
Dim SubKey As String
SubKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
RetVal = RegDeleteKey(HKEY_LOCAL_MACHINE, SubKey)
If RetVal <> 0 Then
MsgBox "An Error Occured While Resetting The System Registry..", , "Warning"
End
End If
End Sub

Private Sub Form_Load()
Command1.Caption = "Choose Executable File To Be Loaded At Start Up"
Command2.Caption = "Reset To Normal The System Registry As Before"
End Sub