Making my application a startup program?

Chopin

New member
Joined
Feb 7, 2005
Messages
2
Location
Seattle, WA
Programming Experience
1-3
Hi,

I want to program my visual basic application to automatically make itself a startup program during run-time. I want to have a button on my form that says "Make me a startup program", and have it execute whatever code is needed to do this. I don't want to have to create an installation file, which is very important. There are two different methods here:

1. The application copies itself (or a shortcut to itself) to the startup folder
2. It edtis the system registry

I do not know how to code either these things, and if there's anyone who could help me out with 1 of the 2 (preferably both though) I would really be greatful. Thanks a lot!
 
1 - To copy the exe to the startup folder use the System.IO.File.Copy method.
2 - registry, here's sample code:
VB.NET:
Dim oReg As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser
Dim oKey As Microsoft.Win32.RegistryKey = _
  oReg.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
If bRunAtStartup Then
    oKey.SetValue("NameOfRegKey", Application.ExecutablePath())
Else
    'You should add error checking
    oKey.DeleteValue("NameOfRegKey")
End If
 
Thanks! I actually learned the registry method already from a reply on another forum, but you are the first person to tell me the file-copy thing. I plan to use both in my code so this is very helpful.
 
To add to Paszt's post with the system.IO.Filecopy() method you'd want to use the type system.environment.specialfolder to get the startup folder.

TPM
 
Back
Top