.exe 有几个可能的条目

.exe with several possible entries

我有一个 VB.NET 程序,它在 "normal use" 中显示一个欢迎表单并执行它所做的任何操作,但它也应该可以在绕过表单的模式下从批处理中调用。 我试过了:

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

和批次:

MyProgram.exe "YES"

表格显示...

要获取从命令行发送的参数,您需要使用以下内容,然后适当使用。您发送的 "YES" 参数是字符串,因此当您检索它时 属性 确保将其转换为布尔值 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