In Command Prompt (
cmd.exe), you can set environment variables using
and access them using
They will also be put into the environment of that
cmd.exe process, and inherited by all processes you run from it. If you run bash inside this cmd window, it will have the same variable as
$var. If you run python, it will have
os.environ['var'], and so on.
However, environment variables can be only inherited. If you change a variable in cmd or bash, it will not update the environment of all other running processes, or those you start from Explorer, or those you start from Start menu.
The only exception to the above limitation is when the program can be told to re-read environment from another source; for example, if you use the environment configuration UI at Control Panel → System → Advanced System Settings → Advanced → Environment Variables, Explorer will re-read the environment from registry.
Finally, remember that
%PATH% is a special variable, holding the locations of commands you execute. Don't set it to just anything; use
%mydir% or whatever else instead.