SETTING .NET APPLICATION TO RUN ON WINDOWS STARTUP

It becomes sometimes tricky and difficult just to set your application to run from start up of the operating system.

To start with just create a class like the one below

Imports Microsoft.Win32

 

Public Class RegSettings

‘Setting the source where startup programs runs from the registry

 Const RunAtStartupKey As String = "Software\Microsoft\Windows\CurrentVersion\Run"

 Public Shared Property RunAtStartUp() As Boolean

 Get

 Try

 

Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey(RunAtStartupKey)

‘User_face been the application name the will be stored in the registry

Return CStr(key.GetValue("User_Face", String.Empty)) <> String.Empty

Catch

‘ No errors if something goes wrong.

‘ Just fail silently.

End Try

End Get

Set(ByVal Value As Boolean)

Try

‘ Dim reg As Registry

Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey(RunAtStartupKey, True)

If Value Then

‘setting the source of where the application should run from

key.SetValue("User_Face", Application.ExecutablePath)

Else

key.DeleteValue("User_Face")

End If

Catch

‘ No errors if something goes wrong.

‘ Just fail silently.

End Try

End Set

End Property

End Class

You then create a form add a check box and a button

Add the code below to the button click event

RegSettings.RunAtStartUp = Me.chkStarup.Checked

Where "chkStarup” will be the check box name

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s