In the bat, we need some command return value is stored as a variable,
After repeated testing, and finally come to a normal result
@echo off
setlocal enabledelayedexpansionfor /f "usebackq skip=1 delims=" %%i in (`wmic ENVIRONMENT WHERE "Name='path'and UserName='%computername%\\%username%'" GET VariableValue`) do (
set var=%%i
echo !var!
pause
)
The results are as follows
Parsing:
1, setlocal enabledelayedexpansion is to expand the local environment variable delay, otherwise it will show " ECHO is off ."
set: Set
local: Local (environment variables)
enable: can be
delayed: delay
expansion: Extended
setlocal enabledelayedexpansion
2, the loop usebackq for brackets with marks (with a key ~) instead of single quotation marks'
. 3, Skip Skip first row = 1, for the present example because there are typing the title bar, so removing the first row, started to take the output from the second line
. 4, %% i represents a variable number bis%, cmd expressed in% i, case sensitive while %% i %% I and different
. 5, ! Var! Open after a time delay in the variable enclose