Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows
How do I run a program written with C# at startup?
Posted 31-Oct-10 1:07am
M_Amin580
Edited 31-Oct-10 3:55am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

Most fundamental option is writing a Windows Service is a serious option. It gives important benefits over regular applications, but also more difficult to develop and debug. The service keeps running when users log out and log in.
 
For all other ways, I have a more comprehensive method which I find very robust. You can find all different ways to register application for loading once or on regular basis following SysInternals application called AutoRuns:
 
1) Go to SysInternals site: http://technet.microsoft.com/en-us/sysinternals[^].
2) Download SysInternals Suit: http://download.sysinternals.com/Files/SysinternalsSuite.zip[^]; you can also download separate applications, but there are more useful things, read utilities Index: http://technet.microsoft.com/en-us/sysinternals/bb545027[^].
3) Unpack and run AutoRuns, read it help and look at the top-level items of the tree: they show when you can install your applications.
4) Activate context menu and select "Jump To"; it will open Regedit on a selected item.
5) Write installation application which writes the path to your application and parameters in a right place in the Registry.
 
Good luck,
—SA
  Permalink  
Comments
Espen Harlinn at 31-Jan-11 15:18pm
   
Once more a good answer, and some nice links too, 5+ :)
SAKryukov at 31-Jan-11 16:05pm
   
Thank you,
This is again about learning what's on the system.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to use the Registry for running a program at startup. You can use the RegistryKey class that's in the System.Win32 namespace. The following code shows how to do this:
 
RegistryKey rk = Registry.CurrentUser;
RegistryKey StartupPath;
StartupPath = rk.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
if (StartupPath.GetValue("ProjectName") == null)
{
    StartupPath.SetValue("ProjectName", Application.ExecutablePath, RegistryValueKind.ExpandString);
}
 
Note: RegistryKey is in the System.Win32 namespace, hence don't forget to import it.
  Permalink  
v2
Comments
Dalek Dave at 1-Nov-10 7:25am
   
Good Answer.
MDNadeemAkhter at 3-Nov-10 9:42am
   
5 From Me Good Answer
Chanchal Kumar Ghosh at 16-Nov-10 4:36am
   
+5 Very good answer...
binadi007 at 6-Apr-14 23:45pm
   
What is the purpose of RegistryValueKind.ExpandString?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

use given Link to Run Program at Startup
 
Link[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Hi.
you need to use the registery to run program at sturt up.
you must create a key in "Hkey_current_user\Software\Microsoft\Windows\CurrentVersion\Run".
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

A program can be loaded at startup from various places. One of Which is by placing shortcut to any application in then Windows STARTUP Folder.
 
This is usually located at C:\Windows\Start Menu\Programs\Startup in Windows 95, 98, or ME,
or at C:\Documents and Settings\All Users\Start Menu\Programs\Startup in Windows XP for all user
or C:\Documents and Settings\{USER NAME}\Start Menu\Programs\Startup for specific User.
However, it may be at a different location on your computer if you have tweaked with the configuration.
You can view the Startup folder in Windows Explorer by clicking the appropriate link (immediately above) if you have used the default; or you can view it by clicking Start | All Programs | StartUp.
 
You can place any shortcut or even application in the mentioned folder to run any application at startup.
 

I hope this might work
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,105
1 DamithSL 5,079
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,617
4 Kornfeld Eliyahu Peter 4,384


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 30 Jan 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100