nem33 Posted December 30, 2003 Posted December 30, 2003 For instance: "C:\MyProgram.exe" option1 option2 option3 I'm trying to do this within a form I've tried this method but can't pass any arguments, can only execute the program without options: filename = "C:\MyProgram.exe" System.Diagnostics.Process.Start(filename) Now If I do this: filename = "C:\MyProgram.exe option1 option2" System.Diagnostics.Process.Start(filename) It cannot open the program at all. Quote
*Experts* Bucky Posted December 30, 2003 *Experts* Posted December 30, 2003 Process.Start is overloaded to also take two string parameters. When this overload is used, the second parameter of the function is arguments passed to the program being started. Dim filename As String = "C:\MyProgram.exe" Dim args As String = "option1 option2" System.Diagnostics.Process.Start(filename, args) Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
TMI Posted December 30, 2003 Posted December 30, 2003 Here is how I handle it in my program. Module Startup Public Sub Main() Dim Result As DialogResult Dim Arguments As Object Dim i As Integer Arguments = Environment.GetCommandLineArgs() Dim f As New Form1() If IsArray(Arguments) Then For i = LBound(Arguments) To UBound(Arguments) Select Case i Case 1 curProject = Arguments(i) If curProject.Length <> 6 Then MessageBox.Show("No current project is selected, " & vbCrLf & _ "Please select a project", "Missing project information!", MessageBoxButtons.OK, MessageBoxIcon.Error) End End If Case 2 ProductType = Arguments(i) 'Need to get the first character of the passed argument ProductType = ProductType.Substring(0, 1) If ProductType <> "C" Then ElseIf ProductType <> "T" Then ElseIf ProductType <> "W" Then ElseIf ProductType <> "X" Then MessageBox.Show("Invalid product type, " & vbCrLf & _ "Please select a project", "Missing project information!", MessageBoxButtons.OK, MessageBoxIcon.Error) End End If Case 3 Phase = Arguments(i) If Phase.Length <> 2 Then MessageBox.Show("Invalid Phase id, " & vbCrLf & _ "Please select a project", "Missing project information!", MessageBoxButtons.OK, MessageBoxIcon.Error) End End If End Select Next End If f.ShowDialog() End Sub End Module Quote
AndreRyan Posted December 31, 2003 Posted December 31, 2003 The above code has some errors in it: Public Class Startup 'Use classes not modules, modules are wrapped around a class anyway Public Shared Sub Main() Dim Result As DialogResult Dim Arguments As String() 'Don't use Objects, Objects will cause boxing and unboxing which slows things down Dim i As Integer Arguments = Environment.GetCommandLineArgs() Dim f As Form1 = New Form1() If Arguments.GetUpperBound(0) > 0 Then 'I'm pretty sure IsArray is a compatibility function For i = Arguments.GetLowerBound(0) To Arguments.GetUpperBound(0) 'LBound and UBound are compatibility functions Select Case i Case 1 curProject = Arguments(i) If curProject.Length <> 6 Then MessageBox.Show("No current project is selected, " & vbCrLf & _ "Please select a project", "Missing project information!", MessageBoxButtons.OK, MessageBoxIcon.Error) Return 'End is a compatibility command, it shouldn't be used End If Case 2 ProductType = Arguments(i) 'Need to get the first character of the passed argument ProductType = ProductType.Substring(0, 1) If ProductType <> "C" Then ElseIf ProductType <> "T" Then ElseIf ProductType <> "W" Then ElseIf ProductType <> "X" Then MessageBox.Show("Invalid product type, " & vbCrLf & _ "Please select a project", "Missing project information!", MessageBoxButtons.OK, MessageBoxIcon.Error) Return End If Case 3 Phase = Arguments(i) If Phase.Length <> 2 Then MessageBox.Show("Invalid Phase id, " & vbCrLf & _ "Please select a project", "Missing project information!", MessageBoxButtons.OK, MessageBoxIcon.Error) Return End If End Select Next End If 'Don't use ShowDialog unless it's a secondary form Application.Run(f) End Sub End Class He was asking how to send commandline parameters, not how to read them though Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.