Search code examples
vb.netbatch-fileprogram-entry-point

.exe with several possible entries


I have a VB.NET program that, in "normal use" shows a welcome form and does whatever it does, but that should be also callable from a batch in a mode where the form is bypassed. I tried:

Sub Main(s As String)
    MainSub(False)
End Sub
Sub Main()
    MainSub(True)
End Sub
Sub MainSub(ShowTheForm As Boolean)
    'whatever
end sub

and the batch:

MyProgram.exe "YES"

The form shows...


Solution

  • To get the arguments sent from command line you need to use the following and then use appropriately. The "YES" parameter you are sending is string, so when you retrieve it property make sure you convert it to boolean CBool(arg)

    If Environment.GetCommandLineArgs.Length > 1 Then
            ' Loop and find each argument
            For Each arg In Environment.GetCommandLineArgs
    
                If arg.ToString = "yes" Then 
                     'Do stuff here
                 End If
            Next
    End If