Click here to Skip to main content
15,917,731 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
See more:
Hey to those interested,

So I want to create an application that once published, and thereby creating a setup file, to have it automatically startup when windows starts for any user. Is there a specific way of doing this?

I'm a bit unsure of how to create the code or how the installer will make sure the program runs on startup and create a system tray icon.

One of the methods that I have seen is by creating a registry entry like below, and by looking at the MSDN forums, on creation of a system service, but was confused.
Dim oReg As RegistryKey = Registry.CurrentUser
  Dim oKey as RegistryKey = oReg.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
  oKey.SetValue("MyVBApp", cPGM)

Once the program is written is there a specific way of publishing or will it be the same?

Visual Studio 2008 Express, C# 3.5..........
Posted
Updated 19-Apr-11 22:35pm
v2
Comments
Sergey Alexandrovich Kryukov 20-Apr-11 15:10pm    
Reasonable question, but you should have specify things more clearly. (My 4.) However, I put my answer the way you can use it in all cases.
--SA

The registry location you're trying to use may be not what you want.
You're confused, because even in your Question you did not describe what exactly event should trigger the start of your application.

Not to worry. Consider the following:

First, you can consider creation of Windows Service. This is the ultimate approach: its process is started on system start-up and it keep running when the user's log in/out. The Service process can detect different events in the system and act appropriately. This solution needs essential effort though, especially in debugging. Debugging is still quite possible but needs some learning and extra work.

The simplest (and perhaps the least powerful) option is adding a LNK file to the system Start Menu in the item "Startup" per user. One problem is tracking this change when a new user is added. You can also use the menu item which works for all users. Please see the note made by Kim below (Kim, than you very much for this useful comment.)

Finally, here is my "secret weapon": Sysinternals application "AutoRuns". I used it as an ultimate reference for the information on the topic. Go to Sysinternals Web page, download Sysinternals Suit: http://technet.microsoft.com/en-us/sysinternals/bb842062[^]. You can download separate utilities (see http://technet.microsoft.com/en-us/sysinternals/bb545027[^]), but I recommend all of it — must-have for all developers. Unpack and run AutoRuns, look at all the sections and help. You will find all possible points where your application can be loaded automatically. You can also automatically jump from an AutoRuns item to a corresponding Registry item with RegEdit. Enjoy!

—SA
 
Share this answer
 
v2
Comments
Kim Togo 20-Apr-11 16:05pm    
Good answer SA. Although I'm confused what OP is asking for?

- Creating a TrayIcon in C# ?
- A setup project, that installs the program ?
- Auto startup of program ?

About the LNK file in "Startup" folder. There exists a "All Users" Start Menu -> Startup folder.
A "Startup" folder pr. user and pr. computer.
Sergey Alexandrovich Kryukov 20-Apr-11 16:14pm    
I agree, Kim. That's why I mentioned that OP did not specify exact event which should trigger the application start. And that's why I tried to cover all possible variants. Did I miss any?
(Well, I believe AutoRuns covers all aspects except custom Windows Service, so I added this aproach.)
--SA
Sergey Alexandrovich Kryukov 20-Apr-11 16:18pm    
And thank you very much for your comment on "All users". I fixed my answer and gave you the credit for this.
--SA
Kim Togo 21-Apr-11 1:44am    
Thanks for credit :-)
Sergey Alexandrovich Kryukov 21-Apr-11 2:27am    
No problem at all. Thanks again for your correction.
--SA
Take a look at NotifyIcon[^]

Under Visual Studio 2008, open your Form in the Designer and drag & drop a NotifyIcon.
Remember to give NotifyIcon a icon, text and call Visible = true

this.notifyIcon.Icon = Properties.Resources.MyIcon;
this.notifyIcon.Text = Properties.Resources.MyText;
this.notifyIcon.Visible = true;


For the autorun. Try to start the program "msconfig" and click tab "Startup" it gives a good hint on how other programs do.

You can also put a link in "Start Menu\Programs\Startup" folder to your program.
 
Share this answer
 
v2
Comments
Rojeh 20-Apr-11 8:45am    
gd Answer.My 5
Kim Togo 20-Apr-11 8:47am    
Thanks.

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