Setting environment variables for Windows cmd temporarily, to run a program, in a single line?

You could run a batch file with a setlocal

or on cmd line start another cmd.exe which inherits the current environment but changes are volatile.

cmd /c "SET MYVAR=1&myprogram.exe" 

Try this command:

set Foo=bar & abc.exe & set Foo=

This command does:

  1. Set Foo variable with bar value.
  2. Run abc.execommand.
  3. Unset Foo variable by adding blank value.