← Back to Tiny Hacks

Windows Env Variables

Env variables I use more frequently ...





cd %allusersprofile%
APPDATA C:\Users\{username}\AppData\Roaming
cd %appdata%
CMDCMDLINE The original command line that invoked the Command Processor.
echo %cmdcmdline%
CommonProgramFiles C:\Program Files\Common Files
cd %commonprogramfiles%



but generally, I prefer using "hostname"

echo %computrename%

DATE The current date using same region specific format as DATE.
echo %date%


Note: doesn't include the drive name

cd %homepath%
LOCALAPPDATA C:\Users\{username}\AppData\Local
cd %localappdata%
PATH C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem;{plus program paths}

set PATH=%PATH%;c:\temp

echo %path%
Default executable file extensions to search for and use, and in which order, left to right.
echo %pathext%
ProgramData C:\ProgramData
cd %programdata%
ProgramFiles C:\Program Files or C:\Program Files (x86)
cd %programfiles%

Code for current command prompt format


set prompt=[%ComputerName%\%Username%] $t$_$p$_$_$+$g

>prompt /?
Changes the cmd.exe command prompt.

PROMPT [text]

text Specifies a new command prompt.

Prompt can be made up of normal characters and the following special codes:

$A & (Ampersand)
$B | (pipe)
$C ( (Left parenthesis)
$D Current date
$E Escape code (ASCII code 27)
$F ) (Right parenthesis)
$G > (greater-than sign)
$H Backspace (erases previous character)
$L < (less-than sign)
$N Current drive
$P Current drive and path
$Q = (equal sign)
$S (space)
$T Current time
$V Windows version number
$_ Carriage return and linefeed
$$ $ (dollar sign)

USERPROFILE %SystemDrive%\Users\{username}
cd %userprofile%

%windir% is a regular User variable and can be changed, which makes it less robust than %SystemRoot%
Set by default as windir=%SystemRoot%
%WinDir% pre-dates Windows NT, its use in many places has been replaced by the system variable: %SystemRoot%

cd %windir%

Complete list of variables on Wikipedia: https://en.wikipedia.org/wiki/Environment_variable#Windows