Click here to Skip to main content
15,887,816 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
I have a windows application developed.I need this program to run at startup. What exactly I need is when the windows starts(system starts)
the user should get a popup do you want to start this program, if clicked on yes it should be startted automatically.

Can anyone please provide me code for this?
Posted

You will find THIS[^] question is already posted in CP before and got a huge of popularity.

This I am sure definitely will get you out of trouble.
 
Share this answer
 
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:

C#
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.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 10-Jan-11 10:40am    
This seems to be a verbatim copy of this:
http://www.codeproject.com/Answers/123402/Running-a-program-at-startup.aspx#answer1
I can't see any reference to the originator. Please explain?
fjdiewornncalwe 10-Jan-11 11:15am    
@Sandeep... You should know better.
Sandeep Mewara 10-Jan-11 11:37am    
Guys, I gave a reason to Ravi already(Refer: http://www.codeproject.com/Answers/144199/help-in-TabControl.aspx#answer2). Long back, I saw that and since at that time answers couldn't be bookmarked I copied it. Infact used in one of the projects. I just copied and pasted that here from my project.

Didn't had any intention to say it's my work... never had. But, I can understand your questions. But, if it upsets you all so much, do tell me, I will remove it.
Sergey Alexandrovich Kryukov 10-Jan-11 11:40am    
I commented by above mistake. Sorry. Deleted.
RaviRanjanKr 10-Jan-11 11:51am    
oh my god it my apologies I haven't read your comment. but why you commented there http://www.codeproject.com/Answers/144199/help-in-TabControl.aspx#answer2.
you should commented here.
please forgive me sandeep I am taking you wrong.
I did a simple Google search and this is what I found:
set a program to run at startup c#[^]

This is the first link from 270,000 results[^] that I got.

So you see the power of search engines?! Use them and you will save everyone a lot of time. :thumbsup:
 
Share this answer
 
v3
We are here to giude you while you are struck up.

Not to do your entire homework.

What code you have done so far and where you are struck up?
 
Share this answer
 
Comments
William Winner 10-Jan-11 13:24pm    
I agree...first rule of these forums is

Have you googled it?!
I already answered similar question:

Start application when windows starts[^]

There are several placed to register this thing -- Startup Folder is the easiest but the worst (least universal).

First, consider to create and install Windows Service. This can be a big overkill, I know.

Go to Sysinternals Suite:

http://technet.microsoft.com/en-us/sysinternals/bb842062[^].

Download all -- many very good utilities, but you will need to run Autoruns. Look how it works and read the help: it will give you the ultimate description of all locations (practically, all in registry) where to register your application to start automatically.
 
Share this answer
 
v2
Comments
Sandeep Mewara 10-Jan-11 11:38am    
I replied back to the comment, do drop your feedback.
Comment to answer in this same question thread (http://www.codeproject.com/Answers/144431/Application-to-be-started-at-startup.aspx?cmt=40585#answer5)
Sergey Alexandrovich Kryukov 10-Jan-11 11:41am    
Now, the one who voted "1", go to Sysinternal Suite now and rethink your life...
Sergey Alexandrovich Kryukov 10-Jan-11 11:42am    
@Sandeep: Yes, I know, what's wrong? How would you advice to answer in such cases?
Sandeep Mewara 10-Jan-11 11:59am    
No idea! Had no clue this could be such an issue and raised till CP Admins! :doh:
Sergey Alexandrovich Kryukov 10-Jan-11 12:23pm    
I don't see any issue. I updated the answer a bit.

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