Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do we start the windows application when we start the computer?

In my application I want to update the current date & time in registry.
Posted
Updated 3-May-11 21:57pm
v2
Comments
Dalek Dave 4-May-11 3:57am    
Edited for Grammar and Readability.

There are some ways to do this -

1) Place a shortcut to your application in the start \ startup folder.
2) Create a windows service to update the date and time.
 
Share this answer
 
 
Share this answer
 
public void SetStartup(bool start)
       {
           RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
           if (start)
               rk.SetValue(Path.GetFileName(Application.ExecutablePath).Replace(".exe", ""), Application.ExecutablePath.ToString());
           else
               rk.DeleteValue(Path.GetFileName(Application.ExecutablePath).Replace(".exe", ""), false);
       }
Try This function.And Add "using Microsoft.Win32"
 
Share this answer
 
v2
Just place a shortcut to your windows application in the Startup folder.

it is something like: "C:\Users\[Username]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"


I have never ever created a shortcut myself, but a quick google gave me this code snippet
C#
private void appShortcutToDesktop(string linkName)
{
    string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

    using (StreamWriter writer = new StreamWriter(deskDir + "\\"" + linkName + ".url"))
    {
        string app = System.Reflection.Assembly.GetExecutingAssembly().Location;
        writer.WriteLine("[InternetShortcut]");
        writer.WriteLine("URL=file:///" + app);
        writer.WriteLine("IconIndex=0");
        string icon = app.Replace('\\', '/');
        writer.WriteLine("IconFile=" + icon);
        writer.Flush();
    }
}
 
Share this answer
 
v3
Comments
Member 7891405 4-May-11 5:22am    
how to add my application setup file in startup folder
Wannes Geysen 4-May-11 5:31am    
see my updated solution
Ashishmau 4-May-11 5:32am    
Simplt put ur debug folder in startup folder
Member 7891405 4-May-11 5:37am    
i want to add my application when booting the computer without knowing to customer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900