Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

placing a shortcut in user's Startup folder to start with Windows

I wanted to give my user an option for "Start with Windows". When user check this option it will place a shortcut icon into Startup folder (not in registry).

On Windows restart, it will load my app automatically.

How can this be done?

like image 570
jameslcs Avatar asked Aug 02 '10 21:08

jameslcs


People also ask

How do I add an application to startup in Windows 10 for all users?

Open Run command box by pressing Windows logo + R keys. In the Run command field, type shell: startup and then press Enter key to open Startup folder. Copy and paste the app shortcut from the desktop to this Startup folder and the app will be added to startup.

What is a startup shortcut?

Programs can be added to the startup folder by opening the folder and then pasting a shortcut of the program into the startup folder. A shortcut to a program can be created by right clicking on the item and then selecting "Create Shortcut" from the popup menu. The shortcut can then be dragged to the startup folder.

How do I make links open on startup?

Here's how. Step 1: Open up any web browser on your PC and navigate to the website you wish to launch upon boot. Copy the website's URL from the address bar at the top. Step 2: Now press Windows key + R to launch the Run dialog, type in shell:startup in the box, and press Enter.


2 Answers

you can use the Enviroment.SpecialFolder enum, although depending on your requirements you might look at creating a windows service instead of an app that has to start on startup.

File.Copy("shortcut path...", Environment.GetFolderPath(Environment.SpecialFolder.Startup) + shorcutname);

edit:

File.Copy needs an origin file directory-path and the target directory-path to copy a file. The key in that snippet is Enviroment.GetFolderPath(Enviroment.SpecialFolder.Startup) which is getting the startup folder path where you want to copy your file to.

you could use the above code several ways. In case you've got an installer project for your app, you could run something like this on install. Another way could be when the app launches it checks if the shorcut exists there and puts one there if not (File.Exists()).

Here is a question about creating shortcuts in code also.

like image 169
Patrick Kafka Avatar answered Sep 27 '22 17:09

Patrick Kafka


WshShell wshShell = new WshShell();



            IWshRuntimeLibrary.IWshShortcut shortcut;
            string startUpFolderPath =
              Environment.GetFolderPath(Environment.SpecialFolder.Startup);

            // Create the shortcut
            shortcut =
              (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(
                startUpFolderPath + "\\" +
                Application.ProductName + ".lnk");

            shortcut.TargetPath = Application.ExecutablePath;
            shortcut.WorkingDirectory = Application.StartupPath;
            shortcut.Description = "Launch My Application";
            // shortcut.IconLocation = Application.StartupPath + @"\App.ico";
            shortcut.Save();
like image 34
Waruna Manjula Avatar answered Sep 27 '22 15:09

Waruna Manjula