开发者

How to detect whether application started from startup or started by user?

I'm making a windows forms application in c# that will start in windows start up . User also can start the application from its icon on desktop.I want the applicati开发者_Python百科on to be minimized in system tray if it was started from windows start up and to be in normal windows state if started by user clicking on its shortcut icon. Is there a a way to detect whether the application started by user or by start up ?

EDIT

i am using this code to make application appear on startup

regesiterykey.SetValue("MyApp", Application.ExecutablePath.ToString());


You can add a command line argument to the Startup shortcut, then check for that argument and minimize the program.

You can probably also set the shortcut to open minimized. (Depending on your GUI) (But not with the registry)


Use instead this one:

regesiterykey.SetValue("MyApp /minimized", Application.ExecutablePath.ToString());


when you put your program in the start up, pass in an additional parameter like "-startup", For normal user click, do not pass in this flag. as far as I know, it is very hard to detect it from run time.


Command line parameter is certainly better way, but also the trick with the current directory can be used. If you check program current directory, program started from startup has Windows system directory, unlike manual executing which has a folder where exe file is located.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜