Pass switches/command line args to standard WinForm exe on start up.

Nemesis09

Active member
Joined
Jul 25, 2006
Messages
31
Location
NSW, Australia
Programming Experience
Beginner
Hi,

I've got a pogram that I wrote in vb.net which amongst other things is used to print out a form every friday. This is a standard vb.net winforms exe. This is all working fine although it would be good to automate this hopefully through "scheduled tasks".

Consequently, I'm now trying to add the ability to launch the exe with a switch and have it start up, load the data, print the form and close, all without the user seeing anything.

Something like "form1.visible = false" will be more that sufficient for hiding the form, and I can figure the rest out my self (I hope).

What I'm asking is how do I get the exe to read/accept the switches/arguments passed to it on startup?

Something like C:\Program Files\TimeWatcher\TimeWatcher.exe /autoprint"

Thanks in advance for any sugestions.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,349
Location
Sydney, Australia
Programming Experience
10+
Something like:
VB.NET:
Dim cla As String() = Environment.GetCommandLineArgs()

'The first element is always the executable path itself.
If cla.Length > 1 Then
    'Look for specific arguments here.
    For Each arg As String In cla
        'Ignore the case of the argument.
        If String.Compare(arg, "/autoprint", True) = 0 Then
            'Perform an autoprint here.
            MessageBox.Show("Autoprint")
        End If
    Next arg
End If
 
Top Bottom