Click here to Skip to main content
15,911,762 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want a method that enable me to make my program which is written in c# to run automatically in every time and when i starting windows.
thanks
Posted

C#
using Microsoft.Win32;

// The path to the key where Windows looks for startup applications

RegistryKey yourApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

// Add the value in the registry so that the application runs at startup

yourApp.SetValue("MyApp", Application.ExecutablePath.ToString());


And if you want to stop your application to auto start then

C#
yourApp.DeleteValue("MyApp", false);
 
Share this answer
 
If your app needs to be running all the time and doesn't need to have a user interface, write it as a windows service. Otherwise, just add your app to the autostart folder in the form of a shortcut.
 
Share this answer
 
Comments
Uday P.Singh 16-Sep-11 15:03pm    
my 5!
Put a link to your executable in the start menu's autostart folder.
 
Share this answer
 
You can create a windows service for your application :
Creating a Basic Windows Service in C#
 
Share this answer
 
Use control panel --> Scheduled Tasks --> Add Scheduled Task

Regards!
 
Share this answer
 

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