Click here to Skip to main content
15,900,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI!

I'm making a program and I want it to show a message box if I click on it but if I start it in some other way i don't want it to show the message box, for example:
If the program starts from autostart then it will start without showing the message box but if i click on the program symbol in explorer it will show the message box. Is this possible?

Thank you in advance!
Posted
Updated 10-Jan-11 4:55am
v2

How about using commandline options:
prog.exe /autostart

Regards
Espen Harlinn
 
Share this answer
 
Comments
Dylan Morley 10-Jan-11 11:38am    
+5, best way to do it imo
William Winner 10-Jan-11 12:58pm    
I don't understand how this answers the question...if he types that into a commandline, then it wasn't using autostart...
Dylan Morley 11-Jan-11 7:21am    
True, it's not really telling you where it was started from, more the ability to control whether or not to display a UI. Lots of utilities will come with an option to supply a -[q]uiet switch at command line to suppress any interface

Then like you say in your answer, just modify the autostart entry to provide the 'suppress' switch (/autostart /q /whatever!)
Espen Harlinn 11-Jan-11 7:25am    
True enough, thanks Dylan!
When your program starts, you need to be able, somehow, to tell how it was started.

The best way that I can see to do this would be to change the autostart settings. I am assuming that you used a RegistryKey to set the program to run. If not, then ignore my answer.

Instead of just using the Application.ExecutablePath in the RegistryKey, you would want to provide a commandline parameter, such as Espen suggested.

Then, when your program is started (in the beginning of your apps Main) you check Environment.GetCommandLineArgs() and check to see if your autostart argument was there. If it's there, then show your MessageBox.
 
Share this answer
 
Have you thought of using Visible?

C#
Button2.Visible = false; // to hide button
TextBox1.Visible = false; // to hide textbox
Button2.Visible = true; // to show button
TextBox1.Visible = false; // to show textbox



Just use a workaround based on this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900