I recently spent 40 - 50 hours trying to find code in VB.net to make my program run on start up. First I looked at putting a short cut in the windows startup folder, but that is messy and anoying after a while so I came up with this...
Okay tutorial time
Now, since we are accessing the registry, you will need to import Microsoft.Win32, which contains the part of the .NET Framework that handles the registry.
There are two different registry directories that handle startup items, HKEY_Current_User and HKEY_Local_Machine. Current User will start the program for the current user only, and the Local Machine will start the program for anyone who uses the computer.
To add a startup item to the Current_User, you will have to open the registry key and set the value, like so:
CODE
Private Sub AddCurrentKey(ByVal name As String, ByVal path As String)
Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
key.SetValue(name, path)
End Sub
And to remove it:
CODE
Private Sub RemoveCurrentKey(ByVal name As String)
Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
key.DeleteValue(name, False)
End Sub
Okay thats all well and good but how would you use it?
Well, I am using a Check Box to determine wether or not the registry startup key is set. The "name" and "path" will be set when the function that sets the registry value is called.
CODE
If CurrentStartup.Checked Then
AddCurrentKey("StartupExample", System.Reflection.Assembly.GetEntryAssembly.Location)
Else
RemoveCurrentKey("StartupExample")
End If
Definitions:
StartupExample is the name of the project, and will also be the name set in the registry key. System.Reflection.Assembly.GetEntryAssembly.Location gets the current location of the program to store in the registry key.
Also, another way that you can set the "name" of the startup key other than specifying it, is by using System.Reflection.Assembly.GetEntryAssembly.FullName.
Now, to set the same startup key in the Local_Machine, just change CurrentUser to LocalMachine
(please remember that the registry is like an animal if you pull its bones out it will cease to work, so dont mess it up!

)
Enjoy
Message me If you have any questions