Results 1 to 10 of 10

Thread: Running app at StartUp

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Location
    New York, NY
    Posts
    2

    Exclamation

    I need to run my app when system starts.
    Thanks in advance.
    Regards,
    IROY

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Create a shortcut in the Startup group of the start menu

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    amitabh, that not a good solution, try to add an entry into the following registry path

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Juz paste this code into your project file will do.

    Code:
    'Put this code under a Basic Module
    Option Explicit
    'WIN32API Costant
    Public Const REG_SZ = 1
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public Const ERROR_SUCCESS = 0&
    
    'WIN32 API declaration
    Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
    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         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
    
    Private hCurKey As Long
    
    Public Function SaveSetting(ByVal hkey As Long, ByVal lpSubKey As String, ByVal lpString As String, ByVal dwType As Long, ByVal lpData As String) As Long
    On Error GoTo ErrHandle
        'Data validation
        If hkey = 0 Or lpSubKey = "" Or lpString = "" Then GoTo ErrHandle
        
        'Open the given hkey + subkey
        If RegOpenKey(hkey, lpSubKey, hCurKey) = ERROR_SUCCESS Then
            'Create the given string + value
            If RegSetValueEx(hCurKey, lpString, 0, dwType, ByVal lpData, Len(lpData)) = ERROR_SUCCESS Then
                SaveSetting = 1
            Else
                SaveSetting = 0
            End If
        Else
            SaveSetting = 0
        End If
        RegCloseKey hCurKey
        
    Exit Function
    ErrHandle:
        SaveSetting = 0
    End Function
    Code:
    'Call the function
        'Add data into the registry
        If SaveSetting(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "MyAPP", REG_SZ, "C:\1.exe") = 1 Then
            MsgBox "Data saved"
        Else
            MsgBox "Fail to save"
        End If
    Cheers!

  5. #5
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Thanks Chris, I knew that you could use the registry, but didn't knew the key used for he purpose.

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    amitahb, which key that you don't know there usage? Perhaps I can explain to you?

  7. #7
    Guest
    There different keys you can use are Run, RunOnce and RunService.

  8. #8
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Actually I am confused in usage of all three that Megatron has written. I know that all three are used for more or less the same purpose, but what's their exact operation. Especially, how do Run and RunOnce differ

  9. #9
    Guest
    Run:-Runs everytime Windows starts
    RunOnce:--Runs only once
    RunService:-Runs much before normal Apps start (usually Anti-Virus programs start here)

  10. #10
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Do all three remain same on NT, provided you have the requisite permissions? And do the entries in RunOnce gets deleted after being executed once

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