A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Run the application at Windows startup
Learn how to make your application run at startup using a well placed registry key. Also you'll see how to stop the application from running at startup, and checking its current state.
On Friday, November 18th 2005 at 11:39 AM
By Andrew Pociu (View Profile)
(Rated 4.7 with 75 votes)
Download this project (Visual Studio 2005)
the application run or not run at startup involves a few simple lines of code for operating on the Windows Registry. More exactly the registry key we're interested in is Run. The full path to it is HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run or if you want the setting for all the users of the operating system use HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run.
Before we start, make sure you add the following using directive:
Define a RegistryKey object we're going to use for accessing the path to the Run registry key:
You can change CurrentUser to LocalMachine if you want the application to run at startup for all the users of the operating system.
Now here's the code used to make the current application run at startup:
Of course, change MyApp to the name of your application as you want it to appear in the System Configuration Utility (msconfig.exe which can be opened by typing msconfig at Start Menu -> Run). Application.ExecutablePath.ToString()retrieves the path to the application executable that's currently running, so we don't have to write it ourselves, not to mention that we don't normally know where the user installs the application.
So basically what we did here is add a value to the Run registry key, containing the name of the application and the path to the executable. That's enough for the executable to run at startup.
Now how do we disable the application from running at startup. Obviously, we delete the registry value we just created:
And how do we check the current state of the application to see if it's set to run at startup or not.
Where chkRun is a Checkbox which gets checked if the application is set to run at startup, and unchecked if it isn't.
There are a few other ways of making your application run at startup, such as adding it to the Startup folder of the Start menu, or adding a line to Win.ini, however using the Run registry key is the most reliable and popular method.
|Digg It! Del.icio.us Reddit StumbleIt Newsvine Furl BlinkList|
Rate this tutorial
There are no related tutorials.
Related Source Code
There is no related source code.
C# Job Search