How to add a directory to the Windows path variable

Overview

In this blog we’ll be covering how to add a directory to the Windows path variable.

Windows uses the path variable as a pointer to the directories it needs to search when looking for programs. A program for a Windows computer is simply a set of instructions compiled into an executable file identified with the “.exe” extension

In Windows, when we click on an icon to open a program, (usually a shortcut), the icon will have the path to the executable (or .exe) for the program, associated with it.

If there is no shortcut for the program, for instance when you’ve copied an executable that doesn’t need installing, it won’t have a pointer in the PATH variable.

So to access that program you can either create a shortcut for it, or if you’re running the program from the command line, either change to the directory it’s in or add the directory that it resides in, to the Windows PATH variable.

Finding the path to a Windows Program

1; If you know which folder the “.exe” file is in you can simply browse to the location and left click with the mouse in the browser bar at the top of the file explorer window and you’ll see the path as below.

How to add a program to the Windows PATH variable. Finding the path.
Finding the path using the file explorer

2; Select the text by left-clicking in the browser bar then holding and dragging the mouse across the text until all of it is blue, then right-click the text and select copy from the pop-up. You can paste the copied text into the path variable in a later step.

3; Another way of finding the executable is to open the command prompt. You can do that by clicking the Windows Start button, then typing “cmd” in the search bar and finally clicking on the “Command Prompt” icon in the list shown.

Opening the Command Prompt in windows 10
Opening the Command Prompt in Windows 10

4; Once the command window is open type in “where” and press the return (or Enter) key. This will show the help for the “where” command.

How to add a program to the Windows path variable, showing the "where" help menu.
The “where” help menu as seen in the windows command prompt

5; We want a command similar to the one outlined in red above. If we were looking for openssl.exe, then we’d need to type in, “where /R c:\ openssl.exe” so we’re recursively (/R) searching from the root directory (c:\) for the pattern “openssl.exe”.

Example output of the "where" command in the Windows
Example output of the “where” command in the Windows

6; In the command prompt you can highlight the path as far as the directory “c:\Program Files (x86)\GnuWin32\bin” and then right-click to copy it in preparation for adding it to the PATH variable.

Adding the directory to the PATH variable

7; Since we’ve got the command prompt open already, we can simply type “path” and press return to see the current value of the PATH variable.

How to add a program to the Windows path variable. Showing the PATH variable in the command prompt
Showing the PATH variable in the command prompt

Since our program isn’t in any of the directories shown in the PATH variable and we are not in the same directory as openssl.exe, typing “openssl.exe” produces an error, because the Windows system can’t find the program.

8; We can add our new directory to the PATH variable within the Command Prompt window, but first type “path /?” and press return to see the path help.

How to add a program to the Windows path variable. Showing the PATH help menu in the command prompt
Showing the PATH help menu in the Command Prompt

9; So, we need to be aware that typing “path” followed by our new directory and nothing else will result in removing all the other path variables. Entering “path C:\Program Files (x86)\GnuWin32\bin” will leave us with;

C:\Users\user>path
PATH=C:\Program Files (x86)\GnuWin32\bin

10; So to keep the existing path we need to include %PATH% in the command as follows C:\Users\user>path %PATH%C:\Program Files (x86)\GnuWin32\bin.

Adding the new directory from the command prompt, and keeping the existing path variable.
Adding the new directory, and keeping the existing path variable.

Now when we type the name of our program, “openssl.exe” it runs the program instead of showing the error.

Checking the PATH variable with the GUI in Windows 10

11; We can also check and amend the path variable with the GUI. To access from Windows 10, click the start button and then click Settings.

Clicking the Windows Start button 1 and then clicking the settings icon 2.
Open settings in Windows 10

12; From the next screen type path in the search box and then select “Edit the system environment variables”.

Selecting Edit the system environment variables in Windows 10
Selecting Edit the system environment variables in Windows 10

13; Next, select the Environment Variables button from the Advanced tab of the System Properties dialogue.

Selecting the Environment Variables button from the advanced tab.
Select the Environment Variables button from the advanced tab.

14; From the Environment Variables window, either double click the System Variables Path or select it and click on the Edit button. This will bring up the “Edit environment variable window” where you can edit, change the order of, or add and delete entries.

How to add a program to the Windows path variable. Showing the Environment Variables windows in Windows 10.
Showing the Environment Variables windows in Windows 10

Checking the PATH variable with the GUI in Windows 7

15; On the desktop, right-click the My Computer icon and choose Properties.

Image showing the Windows 7 My Computer icon on the desktop.
For Windows 7 right click on the My Computer icon and choose Properties

16; You’ll then be presented with the System Properties dialogue similar to Windows 10 in step 13 above. Select the Environment Variables button from the Advanced tab.

17; You’ll then see an Environment Variables window and you can double click the Path variable or select it and click edit the same as for Windows 10.

To cut a long story short, the summary

There are occasions when working with Windows that some programs will require you to either start them or use them from the Command Prompt. You’ll either need to be in the same directory as the executable file to start the program, or you’ll need to add the directory where the program resides, to the PATH system variable of Windows.

You can do this either within the Command Prompt itself, or navigate to a GUI or Graphical User Interface.

We covered the steps to use the Command Prompt and also reach the GUI of Windows 10 and Windows 7 above.

If you’re a network engineer and you could use an IPv4 subnet calculator check out the free techiedoodah IPv4 excel subnet calculator spreadsheet and if you get a lot of time hands on rackside and need a tray to put your laptop on, let us know what you think of the Portable Rack Mount Laptop Tray and sign up if you want one. Type with two hands instead of one, be more comfortable, improve your productivity and get out of the server room sooner, (or wherever the rack happens to be).

Techiedoodah blogs are created in the hope that they can help others by giving real-life examples. If this has been useful to you please feel free to leave a comment. If you’re reading this post on the home page, you won’t be able to post comments here, so follow this link to the blog, and then scroll to the comments section at the bottom of the page.

Comments for How to add a directory to the Windows path variable.

Leave a Reply

Your email address will not be published. Required fields are marked *