I got the following code to run the application at windows startup:
private void SetStartup(string AppName, bool enable)
{
string runKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
Microsoft.Win32.RegistryKey startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(runKey);
if (enable)
{
if (startupKey.GetValue(AppName) == null)
{
startupKey.Close();
startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(runKey, true);
startupKey.SetValue(AppName, Application.ExecutablePath.ToString());
startupKey.Close();
}
}
else
{
startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(runKey, true);
startupKey.DeleteValue(AppName, false);
startupKey.Close();
}
}
It works. but I want the program to start minimized (at windows startup only). I didnt find a working code / good explanation how to do it. Can you help me please?
thanks.
Have you tried
If you want to start minimized at windows startup only you can add extra argument to command line, like
myapp.exe --start-minimized
, then you can parse this parameter and detect whether you need to start minimized or not.Since this is only adding a registry key to SOFTWARE\Microsoft\Windows\CurrentVersion\Run which causes the OS to start the app at startup there isn't a lot you can do unless the application you want to startup accepts a command line parameter to start minimized (You could then add the parameter to the executable path of the key).
If this is a necessary function and you can't modify the program to accept a parameter to minimize the only thing I can think of doing would be to write a program that would minimize these apps after the OS has started them.
I have strugled with the same issue, and found a working solution:
In your
program.cs
, handle the parameter, and then pass that parameter toForm1
:In your
Form1.cs
, you can call a function with the passed parameter and minimize the app:For example, with this function i used, if you start the application with the -minimized parameter, then it will start minimized, a notifyicon pops up in the taskbar and a bubble saying the app is started and running in the background.
Don't normally revive old threads but one Easy way including minimize to system tray, for WPF like this:
Your Window class:
Worked first time so had to post. I'm using WPF notifyicon, hence why i needed it to go to system tray on windows startup.
Had a really hard time finding a good answer to this, finally found it in a really old book. On my Forms application, just opened the program.cs and changed
to
and it opens without a flicker directly to the tray. This app was more just a service, so set it to just have a notify icon and exit button when right clicked. Hope this helps!!