Normally, in windows an application is not saved into the
PATH variable of the system for accessing it easily in the command prompt unless the setup (installer) provides this option.
For example, if you try to use an application that provides a console interface without define it as an environment variable, you'll need to provide the entire path to the executable :
C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe http://google.com google.pdf
That’s a lot of typing (the entire executable path
C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe while in other platforms you can execute
wkhtmltopdf http://google.com google.pdf) in the command prompt, especially for something that as developer, you have to run often.
Fortunately, you can customize this behaviour creating environment variables by yourself.
What are environment variables
An Environment variable is an identifier that has a value related to the current environment, like the Operating System or user sessions, it in most of the cases is an absolute path (
After include i.e the EXECUTABLE path in the PATH variable of the system, then you'll be able to invoke the executable directly in the console without provide the full path but only its name:
wkhtmltopdf http://google.com google.pdf
Better, isn't ? However, note that is not bad to use the full path, we just create the environment variable to write less. For example, typing
.exe can be omitted) in the command line on Windows will show you the utilities available for wkhtmltopdf.
To add an environment variable and type less, you need to provide the path to the folder where the executable is located, never the path with executable.
Windows 7 and 8
To open the environment variables menu, press the Windows key to open up the Start Menu or Start Screen, then search for "advanced system settings". Alternatively, you can access this menu if you go to the Control Panel, then Security , finally click on System and click on the Advanced system settings hyperlink in the left hand pane.
Once the System Properties window opens, click on the “Environment Variables” button.
In the System Variables box, look for a variable called
Path. Select that and click on the Edit button.
In 7 and 8, the variable value for Path is nothing more than a long string of text with various locations around the system. In order to add an entry to your path in Windows 7 and 8, you have to precede the new folder with a semicolon, so:
Click ok and you're ready to go.
To open the Environment variables menu, go to Control Panel > System and Security and finally in System. Click on the Advanced System Settings in the left panel.
Alternatively, you can open directly the environment variables menu by pressing Windows + R (Run app) and then type
The System Properties dialog will be shown, to continue click on Environment Variables in the Advanced Tab.
The Environment variables menu will be shown, select the Path variable in the User variables area and click on Edit.
Finally click OK in the Edit environment variable menu and you are ready to go,now you'll be able to write just the name of the executable (without path and extension) anywhere in the command prompt, i.e wkhtmltopdf.
Open a command prompt and try accesing the executable from any path in the system without type the full path: