Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

RunAtStartUp - Run any application at startup, once or multiple times
[ All Languages » VB »  Windows]

Total Hit ( 1929)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
' 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


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.