Skip to content

Instantly share code, notes, and snippets.

@alvonx
Created September 13, 2023 19:24
Show Gist options
  • Save alvonx/1ca1de58ace37eaa1a7ec6c13dac3a52 to your computer and use it in GitHub Desktop.
Save alvonx/1ca1de58ace37eaa1a7ec6c13dac3a52 to your computer and use it in GitHub Desktop.
get and set environment variable
@echo off
:: Define the name and value of the environment variable
set "MY_VARIABLE=MY_VALUE"
:: Set the environment variable using setx
setx MY_VARIABLE "%MY_VARIABLE%"
:: Display a message indicating that the variable has been set
echo Environment variable MY_VARIABLE set to %MY_VARIABLE%
:: Delay for 10 seconds (you can adjust the duration as needed)
timeout /t 10
@echo off
:: Get the value of the environment variable
set "MyVariableValue=%MY_VARIABLE%"
:: Display the value of the environment variable
echo The value of MY_VARIABLE is: %MyVariableValue%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment