0

I have a application that needs to run with windows which I have it successfully doing but I need it to start into the system tray which I also have it doing but this also happens when the user launches it from a desktop icon.

The problem I'm facing now is getting it to start in the tray at start-up while allowing the user to open the application without it disappearing to the tray on the launch.

I've seen this achieved using a launch switch in the start up keys something like c:\program.exe -h and its the -h that makes the application launch in the tray.

Is there something like this possible or is there another way around this?

I have considered things like a registry key that is changed on the first launch for a day and things like that but everything that I have thought of has faults such as with the above if the computer is shutdown and turned on again. Other than creating another application for the start-up I'm not sure how to achieve this.

Please Note: The application can be terminated so having something such as it checking for a existing process and maximizing it if found is not suitable this will bring in other issues. This has also been done to an extent as only one instance can be run at one time but as stated before I could have it launch to tray on first run but if it is terminated and launched again it will go to tray again which is what I want to avoid.

Craig Smith
  • 48
  • 1
  • 8

2 Answers2

0

the application should have an entry in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

and how to write registery key using c#

Microsoft.Win32.RegistryKey key;
key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Names");
key.SetValue("Name", "Isabella");
key.Close();
Saddam Abu Ghaida
  • 6,381
  • 2
  • 22
  • 29
0

Was answered by C# - Is it possible to create a Windows Forms application that can run from the command line with parameters? and what Hans Passant said using a commad line option.

This is the code that I placed into the Program.cs class:

[STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Main_Form main = new Main_Form();
            main.Show();
            foreach (string s in args)
            {
                if (s == "-h")
                {
                    main.Hide();
                }
            }
            Application.Run();
        }

Set of code adapted from Hide form at launch

Community
  • 1
  • 1
Craig Smith
  • 48
  • 1
  • 8