0

How to force my application to start minimized when launched at windows startup through registry key "Run"?

I'm using this code to add my application to Windows Startup through registry, however i don't know how to force it to start minimized (i only want to start the application minimized when it's launched this way, through registry, and not when the user double-click the .exe). Some sample code would be appreciated. Thanks in advance!

RegistryKey startapp = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
startapp.SetValue("MyApp", Application.ExecutablePath.ToString());
AlexC
  • 383
  • 8
  • 17
  • I've read the solution to that question, but honestly i wasn't able to figure out how to do it. If someone can provide some practical sample i appreciate a lot! thanks – AlexC Feb 22 '14 at 23:21
  • A .lnk file is the usual way to do this. If it needs to be auto-generated then use IShellLink, SetShowCmd() method. – Hans Passant Feb 23 '14 at 00:46

2 Answers2

2

The easiest way to do this is to use arguments for your executable. Say your app is called MyApp.exe. If you start it via the registry, you'll do start:

MyApp.exe -minimized

Otherwise, you'll just start MyApp.exe to start the program without minimizing. See command line arguments for more information on using arguments. To start the application minimized, you can do:

this.WindowState = FormWindowState.Minimized;

For more examples of this, see the link that @Dexters provided in the comments.

pyrocumulus
  • 9,072
  • 2
  • 43
  • 53
  • In my Program.cs i've added "string[] args" to Main: `static void Main(string[] args)` And in my code i've added "-minimize" parameter: `startapp.SetValue("MyApp.exe", Application.ExecutablePath.ToString() + "-minimized");` The entry gets added to the registry (it's shown in msconfig.exe > startup), but the application won't start. What am i doing wrong? thanks! – AlexC Feb 23 '14 at 16:58
  • Hard to say. If the same happens without the minimize parameter, perhaps the path to you application is incorrect. Otherwise I don't know. – pyrocumulus Feb 23 '14 at 17:40
  • Thanks for your answer. The path is right. I've also tried the method described in the answer below, but the problem remains. The entry is added to the registry but the application wont start. Maybe it's because it requires admin. privileges... – AlexC Feb 23 '14 at 18:55
  • The application is set to run at startup in the registry, the path is correct, and the problem remains even without the minimize parameter. I've also tried to set the application to not require admin, but the problem remains anyway. This is a desktop application, and i'm running Windows 8.1 set enter directly to the desktop. – AlexC Feb 23 '14 at 21:25
  • 1
    Adding the application to startup folder didn't worked either. What worked was to add the application to the Task Scheduler, with the advantage that it doesn't bring a UAC prompt: http://stackoverflow.com/questions/15191129/selectively-disabling-uac-for-specific-programs-on-windows-programatically – AlexC Feb 24 '14 at 20:21
0

Another solution I can think of would be to create a shortcut for your application and set the property of the shortcut to run minimized, and add the shortcut to the registry rather than the application.

shark92651
  • 83
  • 1
  • 1
  • 6