Fixing the PATH on Windows
How to easily run useful software that you added
When you add software to Windows, you need to have an easy way to run that software. If you are just adding a few graphical tools, you would save them to the desktop and click on the resulting icon. But when you add command-line tools, you would prefer to have them hidden in some directory filled with tools and simply type their name. You could place them with the standard operating system components, but that quickly becomes hard to maintain. A better solution is to create a new directory and modify the user's PATH.
Commonly-used operating systems use a PATH
environment variable.
Linux
and other forms of Unix,
macOS, and Windows all use a PATH associated with
the user's environment.
When you attempt to run some executable program by referencing
its name, the command interpreter searches through the
directories in the PATH looking for an executable program
by that name.
Or, in the odd case of Windows, with that name plus a period
and some extension, e.g., .exe.
The first match wins — the first such program found is run, regardless of whether there happened to be any other executable programs by that name in later PATH directories.
Until the arrival of Windows 10, the Windows operating systems did not come with SSH and other useful secure networking utilities. So, you would need to add PuTTY or a commercial alternative.
The problem is that you would have to either install the
PuTTY binaries in a system directory,
or else type long path names every time you use them.
The goal would be to simply type pscp
instead of c:\Users\myname\putty\pscp
in the following:
Command Prompt |
c:\Users\myname\Documents>c:\Users\myname\putty\pscp *.ppt server:archive/
|
So let's say you have pulled down
pscp.exe,
psftp.exe,
and
putty.exe
from
the PuTTY download page
and installed them in the new directory c:\bin.
Our problem is therefore adding c:\bin
to the
PATH environment variable.
This is where things get a little strange.
The PATH variable is an aspect of the user's environment. It is set when the user authenticates to the operating system and a session is established. It can be modified within that session, but it is a part of the session environment and it is discarded at the end of that session.
Your first task is finding where this is set. It depends on your version of Windows.
Modifying PATH on Windows 10
Click the Start button, then type
env
and select
Edit the system environment variables.
The below window will appear.
Select Environment Variables.
Click Path in the bottom pane of the new window, and then Edit.
Below is what I saw.
The last entry should have worked,
as the OpenSSH client binaries are stored in
C:\Windows\System32\Openssh\
.
I suppose the %SYSTEMROOT%
variable is mis-set.
Oh well, I'll add another entry to the end of the list.
I clicked on that last entry, then on New,
and then added a new entry with the literal path:
C:\Windows\System32\Openssh\
.
Log off, log on, and it works.
On the (in)security of the Windows PAHT
You will notice that ".
" is not a member of PATH.
However, if you happen to be in the same directory as an
excutable you can run it simply by typing its name.
How does that work?
In Windows, ".
" is always a component of your
PATH and there is nothing you can do about it.
That's right — in operating systems it is
considered best practice for security
to leave ".
" out of the command search
path, especially for privileged users, and especially
for the system administrator.
Windows behaves the opposite way.
Jim Allchin was a vice-president and later, a co-president, of Microsoft. Allchin was co-president of Microsoft's Platforms & Services Division, he was the manager of the Vista project, and led the development of a number of Microsoft's operating systems. Jim Allchin was Microsoft's guy in charge of operating system design. He has provided some interesting insights, as in the following memo he sent to Bill Gates and Steve Ballmer, referenced here, here, here, and here.
I am not sure how the company lost sight of what matters to our customers (both business and home) the most, but in my view we lost our way. I think our teams lost sight of what bug-free means, what resilience means, what full scenarios mean, what security means, what performance means, how important current applications are, and really understanding what the most important problems [our] customers face are. I see lots of random features and some great vision, but that doesn't translate into great products. I would buy a Mac today if I was not working at Microsoft. [...] Apple did not lose their way. [...]
Modifying PATH on Windows 7
On Windows 7:
Click on the start button,
right-click on Computer and select
Properties.
Another new window will appear.
Click Advanced system settings in the new window.
At this point you should have a window named System Properties. Click on its Advanced tab.
On the Advanced panel, click on the Environment Variables button. A new window will appear, as shown here.
Now that you are looking at the list of system environment variables, find the Path value in the list. You may have to scroll down to find it. Click on the Path value to highlight it as shown here, and then click the Edit button.
A new window will appear with the current value highlighted. Do not remove or change the current value, or you will wreck your user settings!
You will see that the PATH variable already has a default value of something like the following:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
The semicolons separate the values, so there are three
components in this default PATH:
%SystemRoot%\system32
%SystemRoot%
%SystemRoot%\System32\Wbem
You want to add
;\bin
to the end of that list, so it becomes something like this.
However, do not change the entire string
to this example!
Leave the existing PATH assignment as you find it
and simply add your new directories.
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;\bin
At this point, you do not need to reboot. Really! This is pretty amazing, a Windows configuration change that does not require at least one reboot!
Any existing command prompts will, of course, still have their original PATH. But newly started one will get the updated PATH. It would be a good idea to immediately start a new one and test your changes.
Modifying PATH on Windows XP / 200*
Right-click on My Computer and select Properties.
Make certain that you are right-clicking on the
My Computer item itself and not some "shortcut"
lurking on your desktop.
Correct:
New window is titled "System Properties" and has
seven tabs in two rows as seen below (Windows XP/200*)
or five tabs (Windows 7).
Wrong:
New window is titled "My Computer Properties" and has
two tabs.
Make the change already described above for Windows 7. Or, better yet, upgrade from early 2000s Windows to a more capable and more secure operating system!
wmic
Installing Windows within a QEMU emulator on a UNIX desktop
Installing Office 2007 on Windows XP
Back to the Linux / Unix page