question

SharpWindows avatar image
0 Votes"
SharpWindows asked SharpWindows commented

Problems with startup parameters

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);
}

         }
dotnet-csharpwindows-forms
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

What i am trying to do -> code i wrote
I get errors from csc file.

0 Votes 0 ·

i get errors from csc file, though

0 Votes 0 ·

Thanks @Viorel-1 for answering

0 Votes 0 ·

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered Viorel-1 edited

Try another Main function:

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.