Command Line Paramater

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to add a paramater to opening the application?

For instance. If I have a windows form that will modify a registry value,
and I'd like to set it up so that it either closes after it runs, or it stays
open. What I'd like to do is add a paramater to the command line that will
indicat this. Like:

c:\editreg.exe -close

and the "-close" paramater would be passed into a variable somehow that
would allow me to program it so that the program would automatically close
when it's finished running...

Any other ways I can accomplish this?
 
Casey said:
Is there a way to add a paramater to opening the application?

Add this code to a module file and select 'Sub Main' as startup object in
the project properties:

[VB.NET]
\\\
Public Module Program
Public Function Main(ByVal Args() As String) As Integer
For Each Arg As String In Args
Console.WriteLine(Arg)
Next Arg
End Function
End Module
///

[C#]
\\\
public static void Main(string[] args)
{
foreach (string arg in args)
Console.WriteLine(arg);
}
///
 
Casey said:
Is there a way to add a paramater to opening the application?

For instance. If I have a windows form that will modify a registry value,
and I'd like to set it up so that it either closes after it runs, or it stays
open. What I'd like to do is add a paramater to the command line that will
indicat this. Like:

c:\editreg.exe -close

and the "-close" paramater would be passed into a variable somehow that
would allow me to program it so that the program would automatically close
when it's finished running...

Any other ways I can accomplish this?

Just modify your Main method so that it takes an array of strings, and
that array will be the command line parameters.
 
oh! score! sounds easy enough.

Jon Skeet said:
Just modify your Main method so that it takes an array of strings, and
that array will be the command line parameters.
 
Back
Top