0
votes

I have a (.NET) program that boots automatically when Windows starts up. However, I don't want the main GUI window to show (I would have it hidden away in the tray).

However, I want the window to of course show when the user opens the program in the normal way from the taskbar/quicklaunch.

What code can I use to solve this problem?

To add the registry key I use to load the program on Windows reboot, here is the code:

RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

rk.SetValue(softwareName, Application.ExecutablePath.ToString());
2

2 Answers

4
votes

Just add a command line argument in the Startup shortcut or the registry's Run key, like /hidewindow.

Then in main(string[] args) check if args.Any(a => a == "/hidewindow") and don't show your window.

4
votes

When you register the program in the auto run section, append a command line key, e.g. /silent.

In the program, handle this key to hide yourself.

Related reading: How can I detect that my program was run from Task Scheduler, or my custom shortcut, or a service, or whatever.