Results 1 to 9 of 9

Thread: Run when computer starts?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Location
    England
    Posts
    242

    Run when computer starts?

    how would i run the application as soon as the user starts their computer?
    Lpeek

  2. #2
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Put a shortcut in the startup. This can be done during setup. It should be in your deployment wizard and if it's not, change what you use to create your setup files.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  3. #3
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    You could either put a shortcut to your program in the Startup folder in the start menu, or you could use the registry here
    Code:
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

  4. #4
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Heh, beat me to it

  5. #5
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    lpeek, please stop asking your questions in new threads when they have already been answered in other threads. This is both rude and annoying. If something doesn't get fully answered, bump your old thread. Do not create a new one. That adds clutter to the boards.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  6. #6
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    If you wanna do it via code...

    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

    There's an API method of returning the exact executeable path\filename of an application and it's more robust than the method I used so I recommened it if you've got the time.

    -adehh

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Location
    England
    Posts
    242
    the bits that say:

    Public Const REG_SZ = 1
    Public Const HKEY_CURRENT_USER = &H80000001

    Are in red and say:
    Constants are not allowed as public members of object modules
    Lpeek

  8. #8
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    10 aussie dollars that you didn't put that portion of code in a Module like adzzzz said

    If there in a Form - use Private!




    Bruce.

  9. #9
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Hold on a second. Are you asking how to start an app when Windows loads up, or when the computer is turned on?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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