views:

59

answers:

3

Is it somehow possible to detect whether program was started by a user or it was started automatically from registry at Windows start up?

+6  A: 

The simplest way i know of would be to add a "--startup" or similar option to the command line for the startup shortcut (or the value in Run), and check for that in your app. If it's there, then the app is being run by Windows; otherwise, the user is running it.

cHao
+1  A: 

Another option would be to get the current process and check the Parent property. Processes started by a user will have explorer as their parent. (Or some other app that launched them). The processes launched at startup will have a different or non-existent parent.

Mark H
+1  A: 

My solution:

string[] args = Environment.GetCommandLineArgs();
if (args[1] == "-hide")
{
//Hide
}
Badr Hari