Results 1 to 9 of 9

Thread: running on startup

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    108

    running on startup

    what is a fool-proof way that i can make my program run when the computer boots up?

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

    Re: running on startup

    One way to have your application load when Windows starts is to place an entry in:
    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

    You're unlikely to find a "fool-proof" way, the user is always going to have the last word.

    Regards,

    - Aaron.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    108

    Re: running on startup

    ok, now i know where to head but is there a way i can have my application put the entry in there?

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

    Re: running on startup

    Quick and dirty:
    VB Code:
    1. Option Explicit
    2.  
    3. 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
    4. Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    5. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    6. Private Const HKEY_LOCAL_MACHINE = &H80000002
    7.  
    8. Public Sub AddToStartup(ByVal sDesc As String, ByVal sFile As String)
    9.     Dim lRegKey As Long
    10.     RegOpenKey HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", lRegKey
    11.     If lRegKey Then
    12.         RegSetValueEx lRegKey, sDesc, 0, 1, ByVal sFile, Len(sFile)
    13.         RegCloseKey lRegKey
    14.     End If
    15. End Sub
    Usage:
    VB Code:
    1. Call AddAppToStartup("My Application", "MyApp.exe")
    Regards,

    - Aaron.

  5. #5
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: running on startup

    take a look at this thread also

    http://vbforums.com/showthread.php?t=397508
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: running on startup

    What kind of app is it that you are attempting to run on computer start up? What does it do?

  7. #7
    Junior Member
    Join Date
    Apr 2006
    Location
    India
    Posts
    29

    Re: running on startup

    The easiest way is just "create an Shortcut" of your application and paste it in the Start-Up folder thats it..., The Appl will run whn ever the system starts.

    Kalyan

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: running on startup

    Quote Originally Posted by JayWalker
    ok, now i know where to head but is there a way i can have my application put the entry in there?
    Although Aaron Young has supplied a very nice little code snippet to programmatically place your app name in the registry so it will execute at boot time, I always wonder why anyone would want to do that.

    That registry entry will be made EVERY SINGLE TIME your application is launched. Is that really necessary? You only need to do it once.

  9. #9
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: running on startup

    It ALWAYS sounds suspicious and there is no legitimate reason any novice should be doing that.

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