Question

I want my users to be able to have my program open on startup. I am coding in vb.net. How can I go about doing this?

I can't find a "system startup" folder anywhere that I could just copy a shortcut to.

Thanks for the help!

Was it helpful?

Solution

Use the registry to write the name (key) and full path (value) of your program.

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

Note this will load when the user logs in, not when the system starts. You need a service as joel said to do this.

In c#.net do this :

public string GetRegistryValue(String key)
{
   return Convert.ToString(Registry.GetValue (@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", key, ""));
}

public void SetRegistryValue(String key, String value)
{
   Registry.SetValue (@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", key, value);
}

VB.net code is very similar.

OTHER TIPS

Use Environment.GetFolderPath to get the Startup folder.

If you want your program to run on system startup, you need to build it as a service. More likely, you want it to run when the user logs in. To do that, you can configure an installer project in your solution to put an icon in the startup folder when the user clicks a radio button during install.

There are a few places where automatic startup applications are registered. In Windows XP and Vista, one such location is in a user's "Startup" folder.

C:\Documents and Settings\<username>\Start Menu\Programs\Startup

I believe this is the recommended location for applications to register themselves for startup. Most installation packagers will offer the option of registering your application for automatic startup when an .msi or other installer is built and run.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top