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.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Run the application at Windows startupLearn 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 72 votes) |
|||||
|
The Visual Studio 2005 project below includes a tiny sample application with a checkbox which you can use to definy wether or not the application should run at startup. The project can very easily be converted to older versions of Visual Studio. Making 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
|
||||||
|
||||||
Current CommentsThank you :)
Thanks. But... how to do that at the time of installation?
You can either create your own installer, or configure the 3rd party installer software to do that. Most setup programs allow you to do that.
Very nice, now I can start up my apps from startup!!
Good.
Thank you very much.
I tried manuially to edit registry, but when I restart comp there is error in app, but i can start it normally and from startup. What can be wrong?
Thanks in advance!
code for run on start up!!!!!!1
danke schön!!!
cool man
now i can run ma app @ system startup
www.hidden-geek.co.cc
Thank you,I will try this and tell you
thank you very good
..you just saved my life :) ..very good tutorial ;)..congrats!!
This makes the application start on windows startup, but for some reason it "copies" the executable to C:\Windows\System32, is this known?
Btw, i'm using Vista Business edition
thats great...
THAT'S SO COOL THANK , BROTHER .
Thanks a lot......was looking around for suck an app.........I was trying to make a winform app run as a service.....this is a good idea
hi ,
if i am not the administrator of the computer is the registry key LocalMachine available for me to set ?
if not will i get an exception ?
hi ,
if i am not the administrator of the computer is the registry key LocalMachine available for me to set ?
if not will i get an exception ?
Good it helps me
can u tell me how i run exe after every 5 min from start up
its awsome really helpful..thanks for making this
sir... i'm really thankful to you ... it's awesome... very useful to others who are looking for this
Hi Champ,
This is really cool. This is working in Vista also. Thanks*100times. Gr8 Job.
Thanks for this!
I put this in my windows forms extension library. It works great. Thanks a lot!!!
It's very helpful. Thank you!
It's very helpful. Thank you!
Can any body please tell me is this working for Windows Vista
thank you so much
Made it simple, Much appreciated.
hi Thank you very much...
But... how to do that at the time of installation?
I don't know what is 3rd party installer
I want mak einstaller with visual studio .net 2005.
could you tell me how i can it?
Nice Article, it works really well on restarting the system. But i am facing one issue, ie the application stops each time when the session state disconnected(accessing via remotedesktop). Can u pls tell me why this is happening?????
This does not will work in vista, right?
Great! thx u very much
Hi! i tried this in windows 7 and it totally wrecked my user account(windows would freeze at welcome screen). so...is this not applicable for 7?
hi,
I cant understand thz tutorial. plz explain me again, i want to start up my website in startup.
regards,
rev
Very useful, the way of representation is excellent.
Very useful, the way of representation is excellent.
Very useful, the way of representation is excellent.
Very useful, the way of representation is excellent.
Very useful, the way of representation is excellent.
Very useful, the way of representation is excellent.
thanks a lot
That was splendid. You saved my arse!
That was splendid. You saved my arse!
That was splendid. You saved my arse!
thank u from iran.
Thank you :)
Thank you
Thank u from Belgium.
autoRun the application without checkon run at startup
autoRun the application without checkon run at startup
You are one of the people who makes life easier. Thanks.
i am try this is in commit method in installer
( RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\LocalMachine\\Run", true);
rkApp.SetValue("MyApp", Application.ExecutablePath.ToString());)
but i am getting file not found error when i try to install pls help me out
thanks
thank for ur snipet i will try it
and thanks a lot again
it's so very nice project
thanks a lot
you can visit my site and c# sharp code and java script
http://code2all.blogspot.com/
or visit c sharp part only
http://code2all.blogspot.com/search/label/c sharp
Thank you very much.
This is exactly what I was looking for.
Someone mentioned it does not work on Windows 7.
I use windows 7 and works perfectly for me.
Buddy u r great nice code nd nice explanation ...
u r cool dude..great
For those getting a file not found error, try putting the application name in quotes:
rkApp.SetValue("MyApp", String.Format("\"{0}\"", Application.ExecutablePath));
Find serial statistics and/or holograms which may usually be used as indicators the fact that sports jerseys will be valid.
Put everything in a method, and in the catch block you can recall the method (you can say the method calls itself). Use System.Windows.Forms.Cursor.Position to get the cursor position in screen coordinates.I admire the important information you offer within your content. I'll bookmark your web site and have my kids examine up the following typically.
Once you have recreated the problem and captured these steps, you can save them to a file and send it to your support person, who can then open it up and view
if i want to remove this application from the system what i want todo. please helpout. i tested i working goood but, i want to remove this application from my system.
please help me out
very helpful topic
Related Tutorials
Related Source Code
C# Job SearchFrom the creators of Geekpedia, a revolutionary new coupon website!
BargainEZ has coupons codes, printable coupons, bargains and it is the leading source of Passbook coupons for iPhone and iPod touch devices.