Подготовте проект, добавив в него форму. На форму поместите:
- Кнопку с именем Command1
Добавте в форму:
Private 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
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _
(ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) _
As Long
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Sub AddToStartup(ByVal sDesc As String, ByVal sFile As String)
Dim lRegKey As Long
RegOpenKey HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", _
lRegKey
If lRegKey Then
RegSetValueEx lRegKey, sDesc, 0, 1, ByVal sFile, Len(sApp)
RegCloseKey lRegKey
End If
End Sub
Private Sub Command1_Click()
AddToStartup "My App Description", "C:\MyApp\MyApp.exe"
End Sub