I can open Notepad just by typing notepad or notepad.exe in command prompt. But for other installed applications, I have to browse to the location first and then run the .exe file. Why is that? Can somebody explain this?
1 Answer
I have to browse to the location first and then run the .exe file.
This is because your other applications are not in the search path for exectable files.
Windows has a built in environment variable (PATH
) which contains a list of directories. The list is searched when trying to find a command to execute:
When a command is issued at the CMD prompt, the operating system will first look for an executable file in the current folder, if not found it will scan
%PATH%
to find it.
The current path can be displayed by typing PATH
without any parameters on the command line.
For example here is my path:
F:\test>path
PATH=C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\apps\Calibre\;C:\Program Files (x86)\QuickTime\QTSystem\
;;C:\apps\NTP\bin
How do I add a program to the path?
From a command line:
You can use the set
command to do this
set PATH=%PATH%;C:\myapplication
Note:
myapplication
is the directory containing your applicationset
will only set thePATH
for the current commmand prompt.- Use
setx
to permanently change thePATH
From the Windows GUI:
Windows 8
- From the Desktop, right-click the very bottom left corner of the screen to get the Power User Task Menu.
- From the Power User Task Menu, click System.
- Click the Advanced System Settings link in the left column.
- In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab.
- In the Environment Variables window (pictured below), highlight the Path variable in the "System variables" section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon.
Windows 7
- From the Desktop, right-click the Computer icon and select Properties. If you don't have a Computer icon on your desktop, click the Start button, right-click the Computer option in the Start menu, and select Properties.
- Click the Advanced System Settings link in the left column.
- In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab.
- In the Environment Variables window (pictured below), highlight the Path variable in the "System variables" section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon.
Source How to set the path and environment variables in Windows
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- environment variables - Environment variables are mainly used within batch files, they can be created, modified and deleted for a session using the SET command.
- path - Display or set a search path for executable files.
- set - Display, set, or remove CMD environment variables. Changes made with SET will remain only for the duration of the current CMD session.
- setx - Set environment variables permanently, SETX can be used to set Environment Variables for the machine (HKLM) or currently logged on user (HKCU).
-
So if i temporarily create a path and close the command prompt my path will be resetted?– kakkarotAug 14, 2015 at 8:50
-
1If you use
set
then yes, if you usesetx
then no. Please look at the further reading links I provided in my answer.– DavidPostill ♦Aug 14, 2015 at 8:51 -
Note: Start\Run fetches data from fegistry SOFTWARE\Classes\Applications on top of paths from PATH (try "chrome", "acrord32" )– PTwrAug 14, 2015 at 12:41