How to: Enable a Batch Mode for Window Forms Applications
This example uses the My.Application.Startup event to check if the application started with the string /batch as an argument.
To enable a batch mode for a Window Forms Application
Have a project selected in Solution Explorer. On the Project menu, click Properties.
On the Application tab, click View Application Events to open the Code Editor.
Iterate through the application's command-line arguments, and set the Cancel property of the e object to True if one of the arguments is /batch.
When the Cancel property is set to True, the startup form does not start.
If the Cancel property of the e object is set to True, call the main routine for windowless operation.
Private Sub MyApplication_Startup( _ ByVal sender As Object, _ ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs _ ) Handles Me.Startup For Each s As String In My.Application.CommandLineArgs If s.ToLower = "/batch" Then ' Stop the start form from loading. e.Cancel = True End If Next If e.Cancel Then ' Call the main routine for windowless operation. Dim c As New BatchApplication c.Main() End If End Sub Class BatchApplication Sub Main() ' Insert code to run without a graphical user interface. End Sub End Class