0

I've created an application who have an option for create a shortcut on Start Menu for autostart on windows start. All works but I need to do something in order to let the software programmatically understand if software is started by windows (automatically) or by the user.

Now I verify if shortcut exists but I want understand if exists some parameter to use for understand if Windows run program or not.

crazyfrog2
  • 25
  • 1
  • 4

2 Answers2

2

During your setup, have the program start with an argument like

myApp.exe autoStart

This way if your app is started via startup or w/e it will have that command line argument, which you can check like

bool AutoStartMode = false; 

//--somewhere near startup

var args = Environment.GetCommandLineArgs();

if (args != null && args.Any(arg => arg == "autoStart"))
{
   AutoStartMode = true;
}
Kyle Gobel
  • 5,530
  • 9
  • 45
  • 68
0

I recommend using the Run key in the registry for your auto start. You will create a sub key for your app under the run key. The value of your key will be the path to your application and any command line parameters you wish to use. One of the parameters could indicate that the application is being started automatically. Kyle provided an example of how you could check for a specific command line parameter.

Trevor Tubbs
  • 2,097
  • 16
  • 18
  • though your option sounds feasible I hate working with the registry because of permissions set on various PCs/group policies differently, @Kyle Golble's approach is elegant and there are no permissions to check for. That's just my opinion.... – Mo Patel Jul 13 '14 at 00:48