User Guide for Command Line Arguments in Windows

Learning about command-line arguments or switches and how to use them is a step along the road to using your computer more effectively.

Command-line arguments or switches are options or file paths that you can pass to an application on startup. Usually, they are added when you start an application by typing its name into the command prompt. This functionality can also be leveraged in shortcuts to improve your workflow.

Being familiar with command line arguments is essential if you’re using the command prompt fairly often. If you’re not, command-line arguments may seem a little foreign but can still deliver a lot of value to your workflow.

What are Command-Line Arguments?

Let’s Start with the Command Line

When you have a command prompt up, and you have a flashing cursor waiting for a command, that’s the command line. If you type in the correct version of an application’s name followed by Enter, your computer will start it as long as the application is located somewhere in the path variable folders.

If that doesn’t work, it may not be in the paths held in your path variable, meaning you may need to type the program’s full path to get it to run.

You can read more about the path variable in my article here.

Perhaps you’ve never used a command prompt before? You can find it in Windows 10 by clicking Start -> Windows System -> Command Prompt. Other versions of Windows like to place it in different locations, but it usually isn’t too difficult to find.

Here’s what it looks like once you have it open. You may have a different default directory when it opens up, but that doesn’t matter.

Personally, I would rather use Windows Search or Windows Run to find and execute the command prompt application name “cmd” instead. I like that technique because it’s fast and works across Windows OS versions.

In addition, this little command prompt program is versatile when considering command-line arguments, command-line utilities, and batch scripting.

Windows Run
Windows Search

The Command-Line Argument

A command-line argument is a bit of text recognized as valid input to a given software program that can be used when you start an application from the command line. They get added after the software name and need to be separated by a space.

Some applications have limitations on the number of arguments you can pass in, while others can take in a chain of multiple. You’ll have to check the documentation for the software in question to find out.

Command-Line arguments are an interesting property of your software to learn about. Primarily because you probably didn’t know they existed, and if you did, you probably didn’t know to what extent they get used in the software you use all the time.

For example, the Microsoft Office suite and Adobe products both use them. You can discover what hidden functionality exists for your software by searching online for the software by name followed by “command-line.”

Some utilities have documentation built into them, but this is usually found on software that is traditionally command-line only.

For example, you can usually find these little manuals in Windows by typing the software’s name followed by the /? command-line argument. In Linux, the manuals can be accessed using the /man command-line argument. More affectionately known as “man pages.”

What Types of Command-Line Arguments are There?

Command-line arguments come in more than one type. Some examples are:

  1. Switches
  2. Files
  3. Values
  4. Links
  5. Paths
  6. Software add-ins

Switches allow you to turn on and turn off built-in functionality or features for the software. A great example of that is the switches built into the Microsoft Office suite you can find on Microsoft’s site. You can do things like turn off the splash screen that appears on start-up or turn off macros.

Most software that has switches has a reference you can find by searching online. For strictly command-line programs, you should be able to use /? in Windows or /man in Linux.

Files are one of the most common command-line arguments for software that creates and edits files. Other software may take configuration files to set the configuration and make it customizable.

If you have a file that you want to pass into a program regularly, you may decide to use the shortcut method outlined below. Some parameters are simple configuration values that don’t need an entire configuration file.

Links as command-line arguments to a browser are an interesting option since it lets you open a browser to a specific page without changing the home page or right-clicking the Taskbar shortcut. It’s also possible that your application needs access to user-configurable web resources.

Today, most applications have utilities for configuring them; however, passing in a link or an IP address may be directly applicable to a program’s purpose. Or possibly, its purpose is for testing networks or network devices.

Sometimes when you’re running a program from the command line, it’s necessary to tell the computer where to find something or where to save something. That’s where passing in a directory path is necessary.

Even if the program and locations in question are in your path variable, the software that uses the path variable is the command prompt and the operating system. In contrast, third-party software needs the whole path to function properly.

Software add-ins are probably one of the more advanced possibilities better left to install wizards or system admins who know what they’re doing. That being said, it’s interesting to note that some software packages accept them by passing in the file name of the add-in with a complete path. That’s why add-ins are also known as plugins or add-ons.

If you intend to play around with add-in functionality, it’s recommended that you do so on a computer you can afford to have to rebuild. In most cases, you should be able to remove the software that becomes corrupted and then reinstall it, but you won’t really know the extent of what you’re changing until it’s already done. Better safe than sorry!

Simple Command-Line Argument Example

Alright, so let’s go over a simple example. For this, we’ll use a native command prompt program since it will be easier to work with. To do this, let’s go over the simple ‘ping’ application.

Ping is a network program that tests your network connectivity access to another computer by sending a message it knows to bounce back. As part of the process, it will measure and report the message travel time.

If the computer you’re trying to reach doesn’t respond before the ping application times out, it reports it as failed and moves on to the next attempt. Finally, after four attempts, the program gives up and closes.

Because it’s a native command-line program, you can use /? to check the arguments that it will accept. Start by opening a command prompt by searching for cmd or typing cmd into Windows Run. You can open Windows Search by pressing the Windows key and S or Win-S.

Users can open Windows Run with the keyboard shortcut, Win-R. Once you have a command prompt open, type ping /? and press Enter. On Windows 10, you should see something like this.

To use ping, you type in ping followed by an IP address or the target_name URL like www.google.com, which is the target_name.

As shown in the usage portion of /? you can see that if you want to add command-line arguments, they need to be after the word ping and before the answer target if you intend to use more than one at a time, the order shown matters as well.

As mentioned, by default, ping does four tries and then quits. If it can’t reach the target, it will time out and close.

Here’s what it looks like if it’s successful. As you can see, you can enter a website address. That’s actually a good way to test if your internet is working.

I made up an IP address that I know hasn’t been assigned a machine to show what it looks like if it fails.

Ok, so let’s pick an easy command-line argument to try out. Let’s take the IP address that google.com responded with and see if it will tell us its URL with the command-line argument -a. That means we would type:

ping -a 172.217.1.164

Here’s what we get as a response.

As it turns out, the name of the server hosting www.google.com that we pinged before actually has the name, yyz10s04-in-f4.1e100.net which is somewhat to be expected.

BONUS: A useful way to use ping is to set your computer to repeatedly try to reach the address you’re trying to connect to without stopping. The benefit of doing this is that you can try to reach the computer you’re working on from a different machine while you’re working on it to see if it comes up. To accomplish this, we use the command-line argument -t. Then, when you’re ready to stop, the command to stop the pinging is CTRL-C.

In this demonstration, I started the ping application using -t to www.google.com and then put my laptop in airplane mode. Once I turned airplane mode off, the computer was able to restore the connectivity.

The different messages tell us different things. Obviously, when the network connection to the web is active, it can reach www.google.com. When the internet is not accessible, but the local machine’s network card is available, the request times out.

Finally, when the local machine’s network card and the internet are not available, the ping application reports a general failure.

Since all computers and most network devices respond to pings (unless they’re configured not to), it can be a useful way to troubleshoot and check a network. It can also help establish whether or not you can get through a network device or span of cable. Sometimes the simple ping program can save you hours.

How to Add Command-Line Arguments to Shortcuts

So what does this have to do with shortcuts? Well, computer functionality is built upon layers, and this functionality is buried into the shortcut functionality. You can go to the shortcut target and add command-line arguments that add functionality like opening files or modifying behavior.

For example, the Microsoft Office products have a number of them to check out on Microsoft’s site. Microsoft calls them switches, but they’re the same thing.

Ok, so now I’m going to show you how you can turn command-line arguments added to a shortcut into more of a workhorse for you. You can experiment with this, but there are a few things you need to get going.

  1. A parent application that accepts command-line arguments
  2. A Desktop shortcut to the parent application
  3. The command-line argument or set of arguments that you would like to add

The first item on the list really depends on your workflow. If you have a specific application that you use a lot to open up and load a specific file all the time, you have the perfect situation for some automation. What about web links?

Web browsers are an obvious candidate, but at home, you have control over your home page. What about at work? Is there a situation where your IT department controls your home page, and you can’t change it?

How about common forms that you need to access and complete on a daily or weekly basis? Microsoft Office products can make use of templates to improve your workflow. Did you know that you can use a command-line argument to open up a blank template on startup?

With a little bit of time reading about the options, you might quickly find at least one or two possibilities for small improvements to your workflow.

To make a Desktop shortcut to the parent application that you want to leverage command-line arguments in, you can click and drag that program from your Start menu onto the desktop. It won’t actually move the application or take it out of your Start menu.

Instead, you should see a little grey square with the word ‘Link’ as you drag it over. If you’re interested in shortcuts and would like to read more, you can check out my article on shortcuts here.

You can find the third thing you need with a simple Google search that includes the software’s name, followed by the words “command-line.” Some simple examples include:

  • Microsoft Office products
  • Browsers
  • Adobe software

Usually, software companies document these kinds of options online, so if your software has command-line options, you should be able to find a listing of them.

In addition, if you’re using a native command-line program like in the example above, it should have the same little manual you can access on Windows using the command-line argument /?. On Linux, you can access the same type of manual with the command-line argument /man.

Now that you have everything you need, right-click your shortcut and select Properties. You should be on the Shortcut tab by default. In there, you will see the Target field that has the path to the application, including the application name and file extension, but it will be enclosed in double quotations. You don’t want to delete it.

To add a command-line argument, place it at the end in double quotations separated from the original target by a single space.

You can add multiple arguments if your application supports it in the same manner. And that’s it! Every time you open the application using this shortcut, it will run using the specified command-line arguments. What’s really handy is now that you’ve built this, you can place it in the Start Menu as a tile or on the Taskbar.

Don’t forget to give it a unique name by right-clicking it and selecting Rename or by pressing F2 while the shortcut is selected with a single click.

Scroll to Top