dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Feb 17, 2001

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


RunAtStartUp - Run any application at startup, once or multiple times

' Add or remove a program to the list of applications that will
' be automatically launched when Windows boots.
'
' Action can be:
'      0 = delete from list
'      1 = execute only once
'     ELSE = execute always
' APPTITLE is the name of the key in the system Registry, if omitted
'  the current project's title will be used instead
' APPPATH is the complete path+name of the program that must be launched
'  if omitted the current application path is used
'
' TIP: you might use this routine inside the QueryUnload event, when
' the Windows session is closing, so that you can save the current set of
' data and run again the application in the same state when Windows restarts.
'
' NOTE: uses the SetRegistryValue and DeleteRegistryValue functions

Sub RunAtStartUp(ByVal Action As Integer, Optional ByVal AppTitle As String, _
    Optional ByVal AppPath As String)

    ' This is the key under which you must register the apps
    ' that must execute after every restart
    Const HKEY_CURRENT_USER = &H80000001
    Const REGKEY = "Software\Microsoft\Windows\CurrentVersion\Run"

    ' provide a default value for AppTitle
    AppTitle = LTrim$(AppTitle)
    If Len(AppTitle) = 0 Then AppTitle = App.Title
    
    ' this is the complete application path
    AppPath = LTrim$(AppPath)
    If Len(AppPath) = 0 Then
        ' if omitted, use the current application executable file
        AppPath = App.Path & IIf(Right$(App.Path, 1) <> "\", "\", _
            "") & App.EXEName & ".Exe"
    End If

    Select Case Action
        Case 0
            ' we must delete the key from the registry
            DeleteRegistryValue HKEY_CURRENT_USER, REGKEY, AppTitle
        Case 1
            ' we must add a value under the ...\RunOnce key
            SetRegistryValue HKEY_CURRENT_USER, REGKEY & "Once", AppTitle, _
                AppPath
        Case Else
            ' we must add a value under the ....\Run key
            SetRegistryValue HKEY_CURRENT_USER, REGKEY, AppTitle, AppPath
    End Select

End Sub
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date