Violet Giraffe
Violet Giraffe

Reputation: 33607

How to restore all environment variables to default in a batch script

I have a .bat script. It runs some commands and alters/adds some environment variables. Then, at some point I need to revert them all to default as if I'm exiting this script and starting a new one from scratch.
So, I need one of the two:
1. either clear the variables (restore defaults that a fresh cmd session gets);
2. or push all the variables when I start the script and pop later to revert to these values.

How can I do that?

Upvotes: 2

Views: 1639

Answers (2)

Kevin Bridges
Kevin Bridges

Reputation: 186

Have you tried using SETLOCAL? Here is some information on it: http://ss64.com/nt/setlocal.html

Upvotes: 7

Daniel Frausto
Daniel Frausto

Reputation: 113

Have you tried?

  reset:
    set "var=%var*=%"

Upvotes: -1

Related Questions