I am having trouble trying to get Environment.GetCommandLineArgs()to work in an event the StartupNextInstanceway it happens in a form event Load. The code below checks to see if the application received command line arguments and sends the path to a function FileOpen()that basically opens the file in my program by entering the file name in its parameters.
If Environment.GetCommandLineArgs().Length > 1 Then FileOpen(Environment.GetCommandLineArgs(1))
The code above works fine in the event Load, although it doesn't work in the event StartupNextInstance. I also tried the code below to get the path to the args command line file:
Private Sub MyApplication_StartupNextInstance(sender As Object, e As ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance
Dim strFile As String = Environment.CommandLine
If strFile.Length > 0 Then frmMain.FileOpen(strFile)
End Sub
The problem with the above code is that it does not receive the path to the file, but does not receive the file that was used to open the program (using the Open with ... method when right-clicking on the file) it will open the location of the EXE program file .
When I tried e.CommandLine, I received an error message:
A value of type 'System.Collections.ObjectModel.ReadOnlyCollection (Of String)' cannot be converted to 'String'.
source
share