I want to be able to type some executable from the command line in windows and have it run, regardless if I am in the folder where the file is located.
How do I set it up or install it so that I can just type someProgram and have it run regardless of my folder location?
Open your system properties (Right click My Computer->properties) Click the Advanced Tab and the envirnment variables button. Look for Path in the System variables section. Then Either put your program in one of the directories listed in that path, or add the install directory to the list. The latter is probably the better option
You would add the path to that program's directory to your PATH environment variable.
This is, in every common operating system, the purpose of the PATH-variable.
If you are bound to windows, there is a better way to do it case you want to use that extensively: I used to have it set up for A LOT of programs, so I could start my programs by Win-R (like Start->Run or on the command line), type in a few letters of the executable name, take advantage of the MRU-List and start the application.
The drawback of adding all paths of those executable to the path is that it slows down the command execution: Everytime you call a program, all paths have to be scanned. Therefore, the PATH variable should only be used for directories that contain several executables, like a "bin" or "tools" directory.
The better way is to create a proper entry in the registry, many program installers do that by themself, BTW.
is the place to go. You will already see a lot of entries. AFAIK, this would also allow to have two different commands starting the same program, but in different working directories, or different properties.
Unfortunately, I have not yet found any information from Microsoft/MSDN about the parameters one can find, like
RunAsOnNonAdminInstall
orBlockOnTSNonInstallMode
. We can only speculate on that.This will also allow you to "rename" the program without actually renaming the executable file (which could get you in trouble if you update it or if it's part of a larger suite) and migrate smoothly if you switch to another favourite application for a certain task. I had vlc and IrfanView start when I typed "wmplayer" and "ACDsee32" accordingly out of habbit/mistake.
EDIT For reference there is this Microsoft doc about application registration.
You need to have your PATH environment variable set. You can find this in the Control Panel under the System icon, in the "Advanced" tab. Click on the "Environment Variable" button. A second dialog appears with two sections. The top one shows variables that are specific to you, the bottom one, to the entire system. If you want it to just affect you, put the change there, else put it in the bottom.
I'd like to add a modern answer to this question (long-tail philosophy of SO sites).
PowerShell is the modern shell on windows. Chocolatey Nuget is a command-line app. It's tagline is 'apt-get for Windows'.
The pattern that Chocolatey uses (which is cloned from package managers for other platforms):
A program and all its EXEs/DLLs are installed to
C:\Program Files(x86)\MyCompany\MyApp
. But only one EXE is ever used,App.EXE
. So chocolatey doesn't add...\MyCompany\MyApp
to the PATH. There is one folder,C:\chocolatey\bin
, that has one MyApp.bat file per program. Each bat files has one line that runs the full path to the EXE:"C:\Program Files(x86)\MyCompany\MyApp\App.EXE" %*
Even if you don't have Chocolatey, I would recommend the same pattern. Create a
%USERPROFILE%\Documents\bin
folder, and create the .bat file. In PowerShell you can useSet-Alias
to do this, add this to your default profile.ps1 file.