Results 1 to 18 of 18

Thread: Making app run on startup

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    278

    Making app run on startup

    Hey, is it possible so that when the user opens up the application, it will automatically be added to the startup? so that everytime the computer starts up the app will load without the user having to manually add it to the startup??
    Thanks in advance
    "Whether you think you can or cannot, you are always right."

  2. #2
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    In a module:


    VB Code:
    1. Option Explicit
    2.  
    3. Public Const REG_SZ = 1
    4. Public Const HKEY_CURRENT_USER = &H80000001
    5.  
    6. Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    7. Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    8. Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    9. Public 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
    10. Public 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
    11.  
    12. Public Sub SaveSettingString(hKey As Long, strPath As String, strValue As String, strData As String)
    13.   Dim hCurKey As Long
    14.   Dim lRegResult As Long
    15.  
    16.   lRegResult = RegCreateKey(hKey, strPath, hCurKey)
    17.   lRegResult = RegSetValueEx(hCurKey, strValue, 0, REG_SZ, ByVal strData, Len(strData))
    18.   lRegResult = RegCloseKey(hCurKey)
    19. End Sub


    In your form:

    VB Code:
    1. Private Sub Form_Load()
    2.   Dim sAppEXE As String
    3.   sAppEXE = App.Path & IIf(Right$(App.Path, 1) = "\", "", "\") & App.EXEName & ".exe"
    4.  
    5.   SaveSettingString HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", App.Title, Chr$(34) & sAppEXE & Chr$(34)
    6. End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    278
    Thanks, just what I was looking for.
    "Whether you think you can or cannot, you are always right."

  4. #4
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    Cool, this code works perfectly for me,

    But I don't want to take any chances with the registry, how would I write a function that would remove these entered registry settings?

    Greg

  5. #5
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519

    Re: Making app run on startup

    Originally posted by BorT
    Hey, is it possible so that when the user opens up the application, it will automatically be added to the startup? so that everytime the computer starts up the app will load without the user having to manually add it to the startup??
    Thanks in advance
    I would have you program look to see if there is a shortcut to it in the startup folder, and if there isn't then make one or copy the exe over..

    Rudy
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  6. #6
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    The app does not appear in the startup folder....

  7. #7
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    So you would then do one of two things..

    1) FileCopy(CurrentAPP,StartupApp)

    2) Creat a shortcut to the APP in the startup folder. I have code for this, but it is at home. You might find some here on the board if you search.
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    VB Code:
    1. Private Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal _
    2.        lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal _
    3.        lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long
    4.  
    5.  
    6.  
    7. 'Form code:
    8.         Dim lReturn As Long
    9.  
    10.         'Add to Desktop
    11.         lReturn = fCreateShellLink("\Startup", _
    12.         "My App Startup", "C:\Path\To\YourApp", "")

  9. #9
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    I think we're missing each other here, I don't need it to be in startup. I need to remove it from the registry.

    Or are you saying that I should forget writing to the registry, and just create it in the startup folder?

    Greg

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    I'm saying, just put it in the startup folder, forget the registry.

  11. #11
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    Originally posted by mendhak
    VB Code:
    1. Private Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal _
    2.        lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal _
    3.        lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As Long
    4.  
    5.  
    6.  
    7. 'Form code:
    8.         Dim lReturn As Long
    9.  
    10.         'Add to Desktop
    11.         lReturn = fCreateShellLink("\Startup", _
    12.         "My App Startup", "C:\Path\To\YourApp", "")
    I tried this, but I get an error saying unable to find dll, stkit432.dll,
    how do I reference this file...

    Also how does one remove this startup link?

    Thanks

  12. #12
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Isn't it in C:/WINNT/SYSTEM32?
    Attached Files Attached Files

  13. #13
    Hyperactive Member greg_quinn's Avatar
    Join Date
    Nov 2002
    Location
    South Africa
    Posts
    366
    Thanks,

    But it wasn't in my system32 folder... but won't this be a problem, what happens if a PC I install my app to doesn't have this file?

    I can install the file as well, but was just wondering.

    Also, could you please tell me how I can remove the link from the startup menu?

    Thanks
    Greg

  14. #14
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    A shortcut is just a .LNK file. So you can delete it like any other file.

    Delete "C:\whatever\yourmom.lnk"

  15. #15
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    Originally posted by duc
    In a module:


    VB Code:
    1. Option Explicit
    2.  
    3. Public Const REG_SZ = 1
    4. Public Const HKEY_CURRENT_USER = &H80000001
    5.  
    6. Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    7. Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    8. Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    9. Public 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
    10. Public 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
    11.  
    12. Public Sub SaveSettingString(hKey As Long, strPath As String, strValue As String, strData As String)
    13.   Dim hCurKey As Long
    14.   Dim lRegResult As Long
    15.  
    16.   lRegResult = RegCreateKey(hKey, strPath, hCurKey)
    17.   lRegResult = RegSetValueEx(hCurKey, strValue, 0, REG_SZ, ByVal strData, Len(strData))
    18.   lRegResult = RegCloseKey(hCurKey)
    19. End Sub


    In your form:

    VB Code:
    1. Private Sub Form_Load()
    2.   Dim sAppEXE As String
    3.   sAppEXE = App.Path & IIf(Right$(App.Path, 1) = "\", "", "\") & App.EXEName & ".exe"
    4.  
    5.   SaveSettingString HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", App.Title, Chr$(34) & sAppEXE & Chr$(34)
    6. End Sub
    I just can't quite recall where I've seen that code before..

  16. #16
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171


    Has someone helped you? Then you can Rate their helpful post.

  17. #17
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Originally posted by mendhak
    Isn't it in C:/WINNT/SYSTEM32?
    Tsk, bad Mendhak!

    VB Code:
    1. Public Declare Function fCreateShellLink Lib "vb6stkit.dll" (ByVal lpstrFolderName As String _
    2. , ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, _
    3. ByVal lpstrLinkArguments As String, _
    4. ByVal fPrivate As Long, ByVal sParent As String) As Long

    You shouldn't need any extra dlls this way.
    Don't Rate my posts.

  18. #18
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by mendhak
    A shortcut is just a .LNK file. So you can delete it like any other file.

    Delete "C:\whatever\yourmom.lnk"
    I thought kill was for that


    Has someone helped you? Then you can Rate their helpful post.

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