Results 1 to 4 of 4

Thread: Autostart registry

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Posts
    65

    Post

    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?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Code:
    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
    [email protected]
    [email protected]

  3. #3
    Lively Member
    Join Date
    Jun 1999
    Location
    Ireland
    Posts
    96

    Post

    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.

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    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
    [email protected]
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width