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!
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
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
 

Chopin

New member
Joined
Feb 7, 2005
Messages
2
Location
Seattle, WA
Programming Experience
1-3
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.
 

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
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
 
Top Bottom