You need to write to the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run part of the registry. Option Explicit
Const REG_SZ = 1 Const HKEY_CURRENT_USER = &H80000001
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 Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _ (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long 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 RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _ (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, _ lpData As Any, lpcbData As Long) As Long
Private Sub SaveSettingString(hKey As Long, strPath As String, strValue As String, strData As String)
Dim hCurKey As Long Dim lRegResult As Long lRegResult = RegCreateKey(hKey, strPath, hCurKey) lRegResult = RegSetValueEx(hCurKey, strValue, 0, REG_SZ, ByVal strData, Len(strData)) lRegResult = RegCloseKey(hCurKey)
End Sub
Private Sub Form_Load()
Dim sAppEXE As String
sAppEXE = App.Path & IIf(Right$(App.Path, 1) = "\", "", "\") & App.EXEName & ".exe" SaveSettingString HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run" _ , App.Title, Chr$(34) & sAppEXE & Chr$(34)
End Sub
KeithI've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
|