Adding windows application programatically in windows startup

hi experts,

            I have written an windows application. I will just pass the setup files to my client.
After he installs the setup file, the program will start running. But once the system is shut down or restarted. I want that application to be started automatically without any initiation from the user.

I have done this project in c# and i want to attain this programatically.
srk1982Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

-DLinder-Commented:
Registry entries are responsible for application auto start.

Please see the following link for information on getting this up an running.  This example creates a class called 'AutoStart' to facilitate this.

http://blogs.vbcity.com/hotdog/archive/2005/12/08/5733.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
-DLinder-Commented:
Here is a more basic solution that doesn't provide the flexibility of the last:
///  DEFINITION OF AUTOSTART FUNCTIONS
 
using Microsoft.Win32;
 
/// <summary>
/// Utility.
/// </summary>
public class Util
{
    private const string RUN_LOCATION = @"Software\Microsoft\Windows\CurrentVersion\Run";
 
    /// <summary>
    /// Sets the autostart value for the assembly.
    /// </summary>
    /// <param name="keyName">Registry Key Name</param>
    /// <param name="assemblyLocation">Assembly location (e.g. Assembly.GetExecutingAssembly().Location)</param>
    public static void SetAutoStart(string keyName, string assemblyLocation)
    {
        RegistryKey key = Registry.CurrentUser.CreateSubKey(RUN_LOCATION);
        key.SetValue(keyName, assemblyLocation);
    }
 
    /// <summary>
    /// Returns whether auto start is enabled.
    /// </summary>
    /// <param name="keyName">Registry Key Name</param>
    /// <param name="assemblyLocation">Assembly location (e.g. Assembly.GetExecutingAssembly().Location)</param>
    public static bool IsAutoStartEnabled(string keyName, string assemblyLocation)
    {
        RegistryKey key = Registry.CurrentUser.OpenSubKey(RUN_LOCATION);
        if (key == null)
            return false;
 
        string value = (string)key.GetValue(keyName);
        if (value == null)
            return false;
 
        return (value == assemblyLocation);
    }
 
    /// <summary>
    /// Unsets the autostart value for the assembly.
    /// </summary>
    /// <param name="keyName">Registry Key Name</param>
    public static void UnSetAutoStart(string keyName)
    {
        RegistryKey key = Registry.CurrentUser.CreateSubKey(RUN_LOCATION);
        key.DeleteValue(keyName);
    }
}
 
///  SAMPLE USAGE IN YOUR APPLICATION
 
string keyName = "MyProgramName";
string assemblyLocation = Assembly.GetExecutingAssembly().Location;  // Or the EXE path.
 
// Set Auto-start.
Util.SetAutoStart(keyName, assemblyLocation);
 
// Unset Auto-start.
if (Util.IsAutoStartEnabled(keyName, assemblyLocation))
    Util.UnSetAutoStart(keyName);

Open in new window

0
HarryNSCommented:
RegistryKey hklm =Registry.LocalMachine;
            hklm = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);

            // To add your Application at Windows startup
            hklm.SetValue(Application.ProductName, Application.ExecutablePath);

            // To Remove the startup Application
            hklm.DeleteValue(Application.ProductName);
0
JackOfPHCommented:
Other option is to add a shortcut to starup folder
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.