Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


API:add to startup


API:add to startup

Author
Message
n00b
n00b
Forum God
Forum God (383 reputation)Forum God (383 reputation)Forum God (383 reputation)Forum God (383 reputation)Forum God (383 reputation)Forum God (383 reputation)Forum God (383 reputation)Forum God (383 reputation)Forum God (383 reputation)

Group: Forum Members
Posts: 1, Visits: 2
I need my program to start everytime when widows starts.

How can I add my program to STARTUP ?

any API ? or suggestions ?



thanks.
Keithuk
Keithuk
Forum God
Forum God (291K reputation)

Group: Moderators
Posts: 1.9K, Visits: 5.5K
You need to write to the
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

part of the registry. Wink

Option Explicit

Const REG_SZ = 1
Const HKEY_CURRENT_USER = &H80000001

Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _
(ByVal hKey As LongByVal lpSubKey As String, phkResult As LongAs Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As LongAs Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _
(ByVal hKey As LongByVal lpSubKey As String, phkResult As LongAs Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" _
(ByVal hKey As LongByVal lpValueName As StringByVal Reserved As Long, _
ByVal dwType As Long, lpData As Any, ByVal cbData As LongAs Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
(ByVal hKey As LongByVal lpValueName As StringByVal lpReserved As Long, lpType As Long, _
lpData As Any, lpcbData As LongAs 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


Keith

I'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.

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search