Agregar argumentos de línea de comando a la aplicación VB.Net

I have a windows forms based application made by another programmer and I need to add a few command line switches to it's primary output exe so that I can pass arguments like:

program.exe -reinitialise or program.exe -sync

I have found some docs online but all seem to be in C# and are for command line only programs.

This program installs via an .msi and the .exe is only constructed at the end.

Entonces mis preguntas son:

  1. How do I add command line switches to a VB.Net application?

  2. Where/What form do I add the parser to so that the primary output .exe accepts the args?

preguntado el 28 de agosto de 11 a las 00:08

1 Respuestas

Similar to C/C#, you get them as an array. Different from C/C#, you obtain them as a read-only property from the application itself (My.Application.CommandlineArgs)

Code sample on that page (for VB) should show you what you need i think...

Respondido 28 ago 11, 04:08

But where in the forms application does it go - in the first displayed form? How does the application know it was launched from the command line and not a link? - Myles Grey

if it's launched from a link, the link may or may not have passed arguments, so that part isn't relevant. - Brandon Langley

As far as where to put it...if you look at your project settings, there is a defined class and entry point, which by default is your form1. You can choose to place the code there (and read it in the entry point), you can also create a class module and change the project to use that as your entry point, and load your forms from that. VB is very loose about this, which is convenient at times, but irritating at others. - Brandon Langley

By making the application know if it was launched from the command line would mean I could stop the program interface loading and just run the procedures in the background (what I want to do) - I have found this: but for some reason I get "Statement is not in a valid namespace" - Myles Grey

Generlaly, when I do something like this , I use a command argument to tell me to run in batch mode. Sometimes the fact that I have command arguments at all allows me to infer batch mode. It's giving you that error because you did not put it inside one of your program namespaces, or you created a new namespace that is not associated with your program itself. Because it's a method, it belongs inside your primary application class. Here's a link to that error: - Brandon Langley

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.