Every administrator who uses batch scripts is well aware of the built-in environment variables (WinDir, Path, ProgramFiles, etc.). Using them makes your batch scripts a lot more portable on other systems and is overall a rather good practice. For example instead of modifying a batch script for a different system in which the Windows directory is located in a different place you can simply use the WinDir environment variable. We use it like so:
Simply put it between two % to specify that this is an environment variable.
If you often use a particular path or any other kind of value why not create an environment variable just for it?
To do that, simply open Control Panel:
In the right pane, navigate to System and Maintenance:
Navigate to System:
In the left pane click on Advanced system settings. A new window will appear:
In the Advanced tab click on the Environment Variables button and a new window will open:
In the System variables group click the New button (the lower of the two New buttons) and a new dialog will appear:
Enter the name of the variable and its value:
Click OK and there you have it:
Click OK to close the Environment variables window and OK to close the System Properties window. To check if the variable is set simply restart the Command Prompt and use the echo command (do not forget the two %):