Hello all,
I have my c# program set to run when windows starts by adding it to the Windows Registry. It works fine, but here is my problem...
I want the program to start in the system tray, but only when it is started automatically by Windows. If the user double-clicks the program from the desktop, then I do not want the program to start in the system tray. Right now, I can either have it always open in normal window mode or always open in the system tray.
Is there anyway to maybe determine if my program was launched by Windows startup? Or is there an alternative to this problem?
Thanks!
-
Add an argument when started by the registry. You can definitely do this with a batch script, or maybe in the registry directly.
You will see the parameter in the argument to your static main function, and can act accordingly.
-
I would suggest using command line arguments. If the user double clicks on an icon, then the program should start with something like this: myProgram.exe /i and if it starts with Windows, then it should start something like myProgram.exe /w.
You can parse command line arguments in the main of your program. See here:
http://www.c-sharpcorner.com/UploadFile/mahesh/CmdLineArgs03212006232449PM/CmdLineArgs.aspx
BFree : All that can be passed in as command line args. For example, if this were the command line arg: /u="foo" /i="bar", then the args array passed into main would contain two elements. [0] = "/u=foo", [1] = "/i=bar". You can write your own simple parsing methods to parse out what you need.TJB : I would suggest specifying the 'start parameters' of the windows service to indicate that it is being started as a service. When it is started via a shortcut, just don't pass the parameters, then you know its being launched by a user. Not perfect, but should get the job done. -
"I have my c# program set to run when windows starts by adding it to the Windows Registry. It works fine, but here is my problem..."
i want my c# application to start when windows starts.. how do i do this ?? what entries should be made in registry ??
0 comments:
Post a Comment