devxlogo

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

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 functionsSub 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 = "SoftwareMicrosoftWindowsCurrentVersionRun"    ' 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 SelectEnd Sub

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist