Start Application on Startup

Either add a shortcut to Startup folder in Startmenu or add a registry key to CurrentUser\Software\Microsoft\Windows\CurrentVersion\Run.

Create shortcut example:
VB.NET:
'add reference to COM "Windows Script Host Object Library" first
 
Dim shell As New IWshRuntimeLibrary.WshShell
Dim startupPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
Dim x As IWshRuntimeLibrary.WshShortcut
x = DirectCast(shell.CreateShortcut(startupPath & "\calc shortcut.lnk"), IWshRuntimeLibrary.WshShortcut)
x.Description = "Calculator"
x.TargetPath = "calc.exe"
x.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System)
x.Save()

See also "Creating a Desktop Shortcut in .NET Code" article http://www.knowdotnet.com/articles/c...ondesktop.html

Registry example:
VB.NET:
Dim regpath As String = "Software\Microsoft\Windows\CurrentVersion\Run"
Dim regkey As Microsoft.Win32.RegistryKey
regkey = My.Computer.Registry.CurrentUser.OpenSubKey(regpath, True)
regkey.SetValue("CalculatorAtStartup", "c:\windows\system32\calc.exe")
regkey.Close()
 
If you want to change whether your app runs at startup from code then you need to do as JohnH has suggested. If you want to do it from when your app is installed then you should use an installer to create either the shortcut or the registry entry.
 
Is there a place in the project properties or a feature in ClickOnce that allows you to create a shortcut in a folder such as Startup?

I'm not writing a setup for this program, so is there another way, maybe through ClickOnce, to create a registry?
 
No, ClickOnce don't have such advanced features. The ClickOnce technology were not designed with traditional bootstrapper installers in mind (even if it does that with prerequisites), but for web-based deployment.
 
There are free tools around that let you create MSI installers with more power than even the full VS 2005. The problem is they are not necessarily easy to come to grips with. I haven't really tried myself either but Inno with ISTool to make things more visual is one thing you might try. There's also NSIS.
 
Advanced Installer does shortcuts, also with the limited free edition. It's a MSI setup package tool. http://www.advancedinstaller.com/

It also wouldn't cost a flop to check a boolean flag in application settings on application startup, if not already done you make the registry or shortcut (you got both codes already). Very simple. I'm trying really hard here to not be sarcastic, but you do know how to get and set a Boolean value? Sorry about that. :D
 
Back
Top