How to initialize all environment variables in CommandPrompt session WITHOUT re-opening CommandPromp

F

Frank Callone

As well known I can open a command prompt and change Environment variables by a command line like

set PATH=D:\myproj;%PATH%

How to I rest now all prevous changes I made since the start of a command prompt session ?

I don't want to close the current command prompt and re-open it (=that would initialize
the env variables but it would like to do it without a close)

Is there a command like

"init env"

...or similar ?

Frank
 
P

Pegasus \(MVP\)

Frank Callone said:
As well known I can open a command prompt and change Environment variables by a command line like

set PATH=D:\myproj;%PATH%

How to I rest now all prevous changes I made since the start of a command prompt session ?

I don't want to close the current command prompt and re-open it (=that would initialize
the env variables but it would like to do it without a close)

Is there a command like

"init env"

..or similar ?

Frank

Only with a little help from you. When you start a Command Prompt,
you must save your variables like so:

set > c:\set.txt

When you want to restore them then you should run this batch file:
@echo off
for /F "tokens=*" %%* in (c:\set.txt) do set %%*

Opening a new Command Prompt would be much faster . . .
 
T

Tim Slattery

As well known I can open a command prompt and change Environment variables by a command line like

set PATH=D:\myproj;%PATH%

How to I rest now all prevous changes I made since the start of a command prompt session ?

You want to reset the PATH environment variable back to what it was
when you opened the console window? There's nothing builtin that will
do that.

You could store PATH into another variable when you open the window:

set oldpath=%PATH%

Then, when you wanted to go back to the original value:

set PATH=%oldpath%

You could make tiny CMD files to do this for you, in order to save
some keystrokes.
 
B

Bill James

You can set a temporary variable equal to the variable you are going to change, then change it back after you are finished.

set savepath=%path%
set path=%path%;D:\myproj
rem do some stuff
set path=%savepath%
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top