6

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
  • 1
    To the dupe closers - neither of the dupes answers the "Why is that? Can somebody explain this?" parts of the question.
    – DavidPostill
    Aug 14, 2015 at 13:15

1 Answer 1

12

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 application
  • set will only set the PATH for the current commmand prompt.
  • Use setx to permanently change the PATH

From the Windows GUI:

  • Windows 8

    1. From the Desktop, right-click the very bottom left corner of the screen to get the Power User Task Menu.
    2. From the Power User Task Menu, click System.
    3. Click the Advanced System Settings link in the left column.
    4. In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab.
    5. 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.

    enter image description here

  • Windows 7

    1. 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.
    2. Click the Advanced System Settings link in the left column.
    3. In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab.
    4. 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.

    enter image description here

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).
3
  • So if i temporarily create a path and close the command prompt my path will be resetted?
    – kakkarot
    Aug 14, 2015 at 8:50
  • 1
    If you use set then yes, if you use setx 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" )
    – PTwr
    Aug 14, 2015 at 12:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .