Problems with startup parameters

swodniW 141 Reputation points
2021-06-25T16:30:25.55+00:00

Hello
What i am trying to do is: (windows forms)

a program starts another program using Process.Start("second_program.exe","login_key");
when second_program starts it reads the startup parameter and if the login_key is correct it starts the form, if not it shuts down

i dont know how to tell this better. Code will explain better:

PROGRAM1
Process.Start("second_program","correct_key");

SECOND_PROGRAM
static void Main(string args)
{
if(args== "correct_key")
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
MessageBox.Show("Successfully logged in!", "-", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Error", "-", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(-1);
}

        }
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,814 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,164 questions
{count} votes

Accepted answer
  1. Viorel 111.5K Reputation points
    2021-06-25T16:39:11.077+00:00

    Try another Main function:

    static void Main( )
    {
       string [] all_args = Environment.GetCommandLineArgs( );
       string args = all_args.ElementAtOrDefault(1);
    
       if( args == "correct_key")
       . . .
    }
    
    0 comments No comments

0 additional answers

Sort by: Most helpful