How to accept startup parameter in Windows Application?

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

Guest

Hi, All,
I am going to construct a Windows Application for user to download data to
the local PC. Beside interactive with user, I also want the program can be
run as a schedule task. When it runs as a schedule, no GUI will be
displayed, I want to achieve this by providing a startup parameter, said /s.
That is when run interactively, the user can double click the icon of the
program, or type the program name in command prompt; when run as schedule,
the schedule task command will be something like this
"C:\schedule_job\abc.exe /s". I don't know how Windows Application accept
startup parameter.
Please help, thank you very much!

Ka
 
Hi,

This should get you started:

Module Main

Public _mainForm As MyMainForm

Public Sub Main()

Dim commandLine As String = Environment.CommandLine()

' parse command line string here

If commandLine.IndexOf("/s") > -1 Then
RunProcess()
Else
_mainForm = New MyMainForm()
Application.Run(_mainForm)
End If

End Sub


Public Sub RunProcess()

End Sub

End Module

You need to set the project to have Sub Main as startup object of course.

Hope this helps,

Danny van Kasteel
 
In VB.NET add a module to your project and in that
module add the following method:

Sub Main(ByVal CmdArgs() As String)
End Sub

Set this method as your startup method
CmdArgs is an array contaning all of your command
line parameters

The syntax in C# should be similar

/claes
 
Kamiyu Au-Yeung said:
I am going to construct a Windows Application for user
to download data to the local PC. Beside interactive
with user, I also want the program can be run as a
schedule task. When it runs as a schedule, no GUI will be
displayed, I want to achieve this by providing a startup
parameter, said /s.

\\\
Public Module Program
Public Sub Main(ByVal Args() As String)
...
If...Then
Application.Run(New MainForm())
Else
...
End If
End Sub
End Module
///

Select 'Sub Main' as startup object in the project properties.
 
Back
Top