How to check for command-line argument that specifies the location of a file

I need to take in a command-line argument that specifies the location of a file. This is for a desktop application, there is no interface, it being run completely by the command-line. I am not sure if I am on the right path.

That code looks fine. It will only show you the first parameter that is given in the command line, however.
You can use the Environment.CommandLine command to capture the whole command line, which includes the path and filename of the executable that is run.
Once you parse the executable off, you have the raw data that is sent to the executable and not as parameters. This would allow you to put spaces into the filename without needing quotes. I have changed the code to reflect this and posted it with this comment.

It will properly return a filename as ONE string, even if it has spaces in it...as long as it is surrounded by quotes:

C:\Test\application.exe "D:\some folder\with spaces\somexmlfile.xml"

You can keep the default Form from showing at all by setting the Cancel parameter to True.

To get these events...
Click on Project --> Propertes.
On the Application Tab, make sure the "Enable Application Framework" box is Checked.
In the Bottom Right, click on the "View Application Events" Button.
Across the top...
Change the Left DropDown to "(MyApplication Events)".
Change the Right DropDown to "Startup".

So your code might look like:

Namespace My ' The following events are availble for MyApplication: ' ' Startup: Raised when the application starts, before the startup form is created. ' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally. ' UnhandledException: Raised if the application encounters an unhandled exception. ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected. Partial Friend Class MyApplication Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup If e.CommandLine.Count > 0 Then Dim fileName As String = e.CommandLine(0) ' do something with "fileName"... MessageBox.Show(fileName) End If e.Cancel = True ' Shut app down WITHOUT ever showing a Form... End Sub End ClassEnd Namespace

Featured Post

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program.
Download Eclipse installation zip file:
Extract files from zip file:
Download and install JDK 8:
Open Eclipse and …

In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…