Click to See Complete Forum and Search --> : Autostart registry
Insane Killa
Dec 9th, 1999, 07:28 AM
Can anyone give me a code so that when my program is run, it adds it self to the autostart registry so that it automatically starts when windows does?
Aaron Young
Dec 9th, 1999, 08:24 AM
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 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 RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Sub Form_Load()
Dim lRegKey As Long
Dim sApp As String
sApp = "C:\Files\Project1.exe"
'Use HKEY_LOCAL_MACHINE to load it every time
'Use HKEY_CURRENT_USER to load it when ever this user logs in
If RegOpenKey(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run\", lRegKey) = 0 Then
If RegSetValueEx(lRegKey, "My Program", 0, 1, ByVal sApp, Len(sApp)) Then
MsgBox "There was a Problem Adding This Program to the Registry", vbExclamation + vbOKOnly, "Error"
End If
Call RegCloseKey(lRegKey)
End If
End Sub
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net
SteveS
Dec 9th, 1999, 12:19 PM
Aaron, this works fine for Win95, is it the same for WinNT and Win98. The "Run" key doesn't seem to exist in my copy of Win98, but does in Win95.
Steve.
Aaron Young
Dec 10th, 1999, 12:37 AM
It's the same for Win95, Win98 (Which is what I used when I posted the reply) and WinNT (What I'm using right now)..
Are you sure you looked in the right place:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.