Environment Variables Windows 2000/XP

| | Comments (45) | TrackBacks (0)

What environment variables are available in Windows?

List of the environment variables callable in windows 2000. e.g. Open a cmd prompt and type echo %appdata% which should return the full path to your profile's Application Data directory. If calling from a batch file remember to quote the %variable% e.g.

IF EXIST "%appdata%"\workrave\historystats. (mkdir D:\AllMyFiles\Workrave.) ELSE echo Workrave. missing

Here's the list with percentage included:

ALLUSERSPROFILE%ALLUSERSPROFILE%Local returns the location of the All Users Profile.
APPDATA%APPDATA%Local returns the location where applications store data by default.
CD%CD%Local returns the current directory string.
CMDCMDLINE%CMDCMDLINE%Local returns the exact command line used to start the current cmd.exe.
CMDEXTVERSION%CMDEXTVERSION%System returns the version number of the current Command Processor Extensions.
COMPUTERNAME%COMPUTERNAME%System returns the name of the computer.
COMSPEC%COMSPEC%System returns the exact path to the command shell executable.
DATE%DATE%System returns the current date. This variable uses the same format as the date /t command. Cmd.exe generates this variable. For more information about the date command, see the Date command.
ERRORLEVEL%ERRORLEVEL%System returns the error code of the most recently used command. A non-0 value usually indicates an error.
HOMEDRIVE%HOMEDRIVE%System returns which local workstation drive letter is connected to the user's home directory. This variable is set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
HOMEPATH%HOMEPATH%System returns the full path of the user's home directory. This variable is set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
HOMESHARE%HOMESHARE%System returns the network path to the user's shared home directory. This variable is set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
LOGONSERVER%LOGONSERVER%Local returns the name of the domain controller that validated the current logon session.
NUMBER_OF_PROCESSORS%NUMBER_OF_PROCESSORS%System specifies the number of processors installed on the computer.
OS%OS%System returns the OS name. Windows XP and Windows 2000 display the OS as Windows_NT.
PATH%PATH%System specifies the search path for executable files.
PATHEXT%PATHEXT%System returns a list of the file extensions that the OS considers to be executable.
PROCESSOR_ARCHITECTURE%PROCESSOR_ARCHITECTURE%System returns the processor's chip architecture. Values: x86, IA64.
PROCESSOR_IDENTIFIER%PROCESSOR_IDENTIFIER%System returns a description of the processor.
PROCESSOR_LEVEL%PROCESSOR_LEVEL%System returns the model number of the computer's processor.
PROCESSOR_REVISION%PROCESSOR_REVISION%System returns the revision number of the processor.
Program Files%PROGRAMFILES%returns the location of the default install directory for applications.
PROMPT%PROMPT%Local returns the command-prompt settings for the current interpreter. Cmd.exe generates this variable.
RANDOM%RANDOM%System returns a random decimal number between 0 and 32767. Cmd.exe generates this variable.
SYSTEMDRIVE%SYSTEMDRIVE%System returns the drive containing the Windows root directory (i.e., the system root).
SYSTEMROOT%SYSTEMROOT%System returns the location of the Windows root directory.
TEMP%TEMP%System and User return the default temporary directories for applications that are available to users who are currently logged on. Some applications require TEMP and others require TMP.
TMP%TMP%System and User return the default temporary directories for applications that are available to users who are currently logged on. Some applications require TEMP and others require TMP.
TIME%TIME%System returns the current time. This variable uses the same format as the time /t command. Cmd.exe generates this variable. For more information about the time command, see the Time command.
USERDOMAIN%USERDOMAIN%Local returns the name of the domain that contains the user's account.
USERNAME%USERNAME%Local returns the name of the user currently logged on.
USERPROFILE%USERPROFILE%Local returns the location of the profile for the current user.
WINDIR%WINDIR%System returns the location of the OS directory

0 TrackBacks

Listed below are links to blogs that reference this entry: Environment Variables Windows 2000/XP.

TrackBack URL for this entry: http://www.kennethhunt.com/mt/mt-tb.cgi/929

45 Comments

Ed Sanks said:

Do all the variables retain the same name and relative values in all languages? We need to deal with one European language windows machine, and I am wondering if we can assume these variables keep the same meaning as they do in English version of Windows.

TIA,
Ed.

lunatic said:

@echo off
:: similar to above methods but this works
:: get current date/time into vars
:: vars= day month year hour mins secs mili
for /f "tokens=1* delims= " %%a in ('date/t') do set dayname=%%a
for /f "tokens=1* delims= " %%a in ('date/t') do set mmddyyyy=%%a
for /f "tokens=1* delims=/" %%a in ('echo %mmddyyyy%') do set day=%%a
for /f "tokens=2* delims=/" %%a in ('echo %mmddyyyy%') do set month=%%a
for /f "tokens=3* delims=/" %%a in ('echo %mmddyyyy%') do set year=%%a
for /f "tokens=1* delims=:" %%a in ('echo %time%') do set hour=%%a
for /f "tokens=2* delims=:" %%a in ('echo %time%') do set mins=%%a
for /f "tokens=3* delims=:" %%a in ('echo %time%') do set sec=%%a
for /f "tokens=1* delims=." %%a in ('echo %sec%') do set secs=%%a
for /f "tokens=2* delims=." %%a in ('echo %sec%') do set mili=%%a

echo day =%day%
echo month=%month%
echo year =%year%
echo hour =%hour%
echo mins =%mins%
echo secs =%secs%
echo mili =%mili%

sudarshan said:

Is there any variable to open the folder (D-drive)

Nasete said:

For Hamim:

Try Expect or any port of it (there are many). http://expect.nist.gov/
It's a really usefull and strong tool to automate tasks that normally require human operators. (command line)
You can do anything a human can do typing (and more, of course).
There are some tweaks to use it on GUI too.

Timo said:

I think you accidently wrote:
%PPROGRAMFILES%
Instead of
%PROGRAMFILES%

Diane said:

The posting I have entered here does not tell me how to set the environmental variable without having the user going to properties on my computer, advanced, Envirnmental Variables and clicking ok, ok. We can not restart the pc to set the variable and would like information on the set command. Thank you.

Posted by: Chris Harries at November 24, 2005 06:07 AM

Good but users may find the set command more usefull

set can be used to change the value of any of the environment vars and when used without any arguments returns a list of all environment vars currently availible - this is paticularily usefull when you have a number of programs installed that have registered there own vars etc.

Bill Hankel said:

I would like to change the environmental variables on one of our servers to post Temp and TMP files to a different partition (%user profiles%\local settings\Temp.) Since the default is to the C: drive, there are many times when there is not enough room to run install updates on the old 4 GB partition. There is plenty of room on the 14 GB G: partition of that HD. How do I edit the environmental variables to do that?

Chris Harries said:

it might show multiple processors when you only have 1 as you have hyper threading

Daniel Macey said:

Good but users may find the set command more usefull

set can be used to change the value of any of the environment vars and when used without any arguments returns a list of all environment vars currently availible - this is paticularily usefull when you have a number of programs installed that have registered there own vars etc.

rut said:

Something has caused cmd.exe-I think this is it- to show number of processors=2. I only have 1, a pentium 4 3.2ghz. Using win xp pro.
Help!

thanks,
rut

Eglé said:


Is there any variable that returns the OS language?

Thanks!

Great info, just what I was looking for! I just made an improved version of zoomer's post. This version is shorter, more readable and discards the day name so that it also works with day names with another length than 3 characters wide. You can put the text below the line directly into a batch file:

-----------------------------------------------------

@echo off

:: Here is a quick way to split the date into parts.
:: Supports yyyy-dd-mm, yyyy-mm-dd, mm-dd-yyyy, and dd-mm-yyyy,
:: doesn't rely on dashes vs slashes.

for /f "tokens=2,*" %%d in ("%date%") do set today=%%d

echo. | date | find "(yy" > nul
if !%errorlevel%!==!0! (
set year=%today:~0,4%
echo. | date | find "mm)" > nul
if !%errorlevel%!==!0! (
set month=%today:~-2%
set day=%today:~-5,2%
) else (
set month=%today:~-5,2%
set day=%today:~-2%
)
) else (
set year=%today:~-4%
echo. | date | find "(mm" > nul
if !%errorlevel%!==!0! (
set month=%today:~0,2%
set day=%today:~3,2%
) else (
set month=%today:~3,2%
set day=%today:~0,2%
)
)

B.A. van Andel said:

Great info, just what I was looking for! I just made an improved version of zoomer's post. This version is shorter, more readable and discards the day name so that it also works with day names with another length than 3 characters wide. You can put the text below the line directly into a batch file:

-----------------------------------------------------

@echo off

:: Here is a quick way to split the date into parts.
:: Supports yyyy-dd-mm, yyyy-mm-dd, mm-dd-yyyy, and dd-mm-yyyy,
:: doesn't rely on dashes vs slashes.

for /f "tokens=2,*" %%d in ("%date%") do set today=%%d

echo. | date | find "(yy" > nul
if !%errorlevel%!==!0! (
set year=%today:~0,4%
echo. | date | find "mm)" > nul
if !%errorlevel%!==!0! (
set month=%today:~-2%
set day=%today:~-5,2%
) else (
set month=%today:~-5,2%
set day=%today:~-2%
)
) else (
set year=%today:~-4%
echo. | date | find "(mm" > nul
if !%errorlevel%!==!0! (
set month=%today:~0,2%
set day=%today:~3,2%
) else (
set month=%today:~3,2%
set day=%today:~0,2%
)
)

aamar said:

When I open my command line windows in windows xp, It opens up with H:\> drive instead of C:\> drive. I login into network running windows AD/2003 also running Kix as our login script. Any one knows, what caused this to open cmd into user homedrive instead of C:\> and how I can fix for all login users?

Kevin corcoran said:

My month day year stuff just to share, nice place you have here.

echo off
@Rem make var newday
FOR /F "TOKENS=1* DELIMS= " %%A IN ('date/t') DO SET dayname=%%A
FOR /F "TOKENS=2* DELIMS= " %%A IN ('date/t') DO SET mdy=%%A
FOR /F "TOKENS=1* DELIMS=/" %%A IN ('echo %mdy%') DO SET month=%%A
FOR /F "TOKENS=2* DELIMS=/" %%A IN ('echo %mdy%') DO SET day=%%A
FOR /F "TOKENS=3* DELIMS=/" %%A IN ('echo %mdy%') DO SET year=%%A

echo dayname - %dayname%
echo mdy = %mdy%
echo month = %month%
echo day = %day%
echo year = %year%


echo copywrite kevin corcoran 2000-2005 not responsible for misuse or damage.

buckiboy said:

Hi guys. I am using Win 2003 server and some application cant run on it. Does anybody knows how to spoof OS name?

Zoomer said:

%ProgramFiles% is missing in this list. It gives "\Program Files" path which might be different for every Windows language implementation.

Very useful list, many thanks.

Best regards.

zoomer said:

%ProgramFiles% is missing in this list. It gives "\Program Files" path which might be different for every Windows language implementation.

Very useful list, many thanks.

Best regards.

Glen said:

Here is a quicker way to split the date into parts, supports yyyy-dd-mm, yyyy-mm-dd, mm-dd-yyyy, and dd-mm-yyyy, doesn't rely on dashes vs slashes.

:YEAR
ECHO. | DATE | FIND "(yy" > NUL
IF !%ERRORLEVEL%!==!0! SET YEAR=%DATE:~4,4%
IF !%ERRORLEVEL%!==!0! SET YEARFIRST=YES
IF !%ERRORLEVEL%!==!0! GOTO MONTH
SET YEARFIRST=NO
SET YEAR=%DATE:~-4%

:MONTH
ECHO. | DATE | FIND "(mm" > NUL
IF !%ERRORLEVEL%!==!0! SET MONTH=%DATE:~4,2%
IF !%ERRORLEVEL%!==!0! GOTO DAY
ECHO. | DATE | FIND "mm)" > NUL
IF !%ERRORLEVEL%!==!0! SET MONTH=%DATE:~-2%
IF !%ERRORLEVEL%!==!0! GOTO DAY
IF !%YEARFIRST%!==!YES! (SET MONTH=%DATE:~-5,2%) ELSE (SET MONTH=%DATE:~7,2%)

:DAY
ECHO. | DATE | FIND "(dd" > NUL
IF !%ERRORLEVEL%!==!0! SET DAY=%DATE:~4,2%
IF !%ERRORLEVEL%!==!0! GOTO DONE_DATE
ECHO. | DATE | FIND "dd)" > NUL
IF !%ERRORLEVEL%!==!0! SET DAY=%DATE:~-2%
IF !%ERRORLEVEL%!==!0! GOTO DONE_DATE
IF !%YEARFIRST%!==!YES! (SET DAY=%DATE:~-5,2%) ELSE (SET DAY=%DATE:~7,2%)
:DONE_DATE


This is based on the post below

Another way to get '01' instead of ' 1' without changing regional settings is %DAY: =0% where DAY is the name of your environment variable.

This code snippet was only tested with Windows 2000, but should work in most versions of Windows.

Hammocks said:

Get hammocks...Great blog by the way..

Lewis Roberts said:

Good page Kenneth, useful info thanks!

You can get yourself a list of all variables and their values by opening a command prompt and typing "set" (without the quotes of course)

Hector Perez said:

We want to set the following path in window xp
path c:\archivos de programa\archivos comunes\autodesk shared

How i do that

me said:

%PROCESSOR_IDENTFIER% should be,
%PROCESSOR_IDENTIFIER%

Ahmed said:

help
i have a probleme
how can i do the save automatic with date "opperation de savegarde par date"
==> rename the file temp with date sys without me intervention
thanks

Joe Darling said:

Good environment info! I've fixed an XP Pro problem with the %windir% variable - thanks.
I can't run SFC (RPC server not running error) and have been through ALL, and I do mean ALL, the procedures I can find on the web (checked services running, re-installed certificates, re-installed windows, etc.) without any change. I feel that it might be something to do with environment variables because another program (Filemap by BB) will not run, giving the error "Run-time error '76': path not found" which according to the programmer "BB" means the C: drive is hidden or an alias, but that is not the case as far as I can tell. Any clues?

Joe Darling said:

Good environment info! I've fixed an XP Pro problem with the %windir% variable - thanks.
I can't run SFC (RPC server not running error) and have been through ALL, and I do mean ALL, the procedures I can find on the web (checked services running, re-installed certificates, re-installed windows, etc.) without any change. I feel that it might be something to do with environment variables because another program (Filemap by BB) will not run, giving the error "Run-time error '76': path not found" which according to the programmer "BB" means the C: drive is hidden or an alias, but that is not the case as far as I can tell. Any clues?

Earl said:

Would like to change the environmental path for "TMP" and "Temp" to D:\Temp. Its a Larger drive.

Using Windows 2000 Professional

Any help would be appreciated,
Earl

Anubha said:

Hi,
Could you please tell me how can i generalize
C:\Documents and Settings\abawa\My Documents for any user...
Can i use C:\Documents and Settings\%USERNAME%\My Documents?
I need this to set an entry in registry.
Thanks!

Kenneth said:

The following batch file fragment will step through the
specified starting folder (%@FOLDER%) and its subfolders,
and delete all files older than %@AGE%.

It requires the use of Windows NT4 or higher, and several
utilities from the Resource Kit, such as FORFILES and
ROBOCOPY v1.95 or higher.

The folder must be the shortname if entered at the command
line. Longname folders should be entered directly into the
batch file.
http://www.ultratech-llc.com/KB/ASP/FileView.asp?File=/Personal/Files/DelOld.TXT

Robert said:

Hmm, anyone think of an inventive way to create a script or batch file that could delete files, say 7 days old?

Would be a real useful script, to purge old data from temp folders or shared network areas that are temporary directories.

David said:

Is there a way to use environment variables so I can just write for example "david" in Run, and the folder where I have given the path to opens?

Barg27 said:

Where do I change the %USERPROFILE% env var?

Jon Benson said:

RE: time varible.

you can use this to separete out new varibles for %HOUR% %MINUTE%:

for /f "tokens=1-2 delims=: " %%a in ('time /t') do (set HOUR=%%a& set MINUTE=%%b)

Jon Benson said:

Is there a way using evironmental varibles to distingush between Windows 2000 and Windows XP? The show as the same with %OS%.

Will said:

Great info!

I have a question, in Windows 2000 you can redirect the My Documents folder to another location. What would the environment variable be then?

SoddOff said:

---what about "%USERPROFILE%\my documents" ???

You would use:
"%HOMEDRIVE%""%HOMEPATH%"\My Documents

The result would be:
C:\Documents and Settings\YourProfile\My Documents

---what about %ALLUSERSPROFILE%\Documents\

You would use:
"%ALLUSERSPROFILE%"\Documents

The result would be:
C:\Documents and Settings\All Users\Documents


To test this information you can go to a command prompt and type "cd (paste-data-)" then press enter. You should change to those directories.

Good luck

Test said:

For the guys the asked the first question -
Start->Run->'USERINIT' brings up My Documents for the logon. That may help.

Arbor said:

and: What about %ALLUSERSPROFILE%\Dokumente\

Arbor said:

Again: what about %ALLUSERSPROFILE%\Documents\ ?

Kenneth said:

what about "%USERPROFILE%\my documents" ???

:_: said:

Is there a env. variable name for My Documents? And dont say "interenet`s in you hands" :) Is there? The one who written the list of default ones knows?

Dan Wheeler said:

Try this batch file for getting date varibles

There is also a program called Fdate.exe.

It's made for MSdos so you have to make it create batch files for it to work correctly

--------start---------------

:: ------------------------------------------------------------------
:: Batchfile : NewDate.bat
:: Purpose : A routine to parse the current date. Supported formats:
:: MM-DD-YYYY DD-MM-YYYY DD.MM.YYYY DD/MM/YYYY
:: OS : Windows 95+, Windows NT4+
:: Created : Tom Lavedas , 20000717:: Adopted : Frank-Peter Schultze , 20000719:: Revised : Frank-Peter Schultze , 20010620
:: ------------------------------------------------------------------
@echo off
if %1/==:/ goto %2
if NOT %1/==/?/ goto Begin
echo Parses the current date.
echo.
echo [CALL] NewDate
echo.
echo NewDate sets the following variables:
echo.
echo Day of Week : DOW
echo Day : DD
echo Month : MM
echo Year : YYYY
echo.
echo NewDate supports the following date formats:
echo.
echo MM-DD-YYYY DD-MM-YYYY DD.MM.YYYY DD/MM/YYYY
for %%C in (echo. goto:End) do %%C
:Begin --------------------------------------------------------------
echo. | date | FIND "(mm" > NUL
if NOT errorlevel 1 %0 : %OS%Parse MM DD
%0 : %OS%Parse DD MM
:Windows_NTParse ----------------------------------------------------
for /f "tokens=1-4 delims=/.- " %%A in ('date /t') do (
set Dow=%%A&set %3=%%B&set %4=%%C&set YYYY=%%D&goto End)
:Parse --------------------------------------------------------------
for %%C in (md cd) do %%C @tmp@
echo @prompt set _D=$D$_> ~tmp1.bat
%COMSPEC% /e:2048 /c ~tmp1.bat > ~tmp2.bat
call ~tmp2
echo %_D% | FIND "/" > NUL
if NOT errorlevel 1 goto Slash
lfnfor on > "%_D%.-"
ren "%_D%.-" "??? ?? ?? ????"
for %%F in ("??? ?? ?? ????") do set _D=%%F
lfnfor off
:Slash
echo set DOW=%%%3%%>~tmp1.bat
for %%S in ("%3=%%%4%%" "%4=%%YYYY%%" "YYYY=%%1") do echo set %%S>>~tmp1.bat
for %%S in (%_D%) do call ~tmp1 %%S
echo %_D% | FIND "/" > NUL
if errorlevel 1 goto Cleanup
echo @prompt set %4=$%%%4%%$_set YYYY=$%YYYY%$_ > ~tmp1.bat
%COMSPEC% /e:2048 /c ~tmp1.bat > ~tmp2.bat
call ~tmp2
:Cleanup
for %%C in ("set _D=" cd.. "deltree /y @tmp@ > NUL") do %%C
:End ----------------------------------------------------------------
echo Demo: YYYY=%YYYY% MM=%MM% DD=%DD% DOW=%DOW%

--------stop-----------------

blanch said:

logonsever should be changed to logonserver

Rich Pasco said:

Try this: Go to Control Panel, Regional and Language Options, Regional Options, Customize, Time, and change Time Format from "h:mm:ss" to "kh:mm:ss". That should give you the leading zero.

- Rich

G.J. de Bruijn said:

I Want to get the first 2 chars from the current time.
Eg %TIME:~0,2% gives " 1" for 01:23:34
However I don't want that space.
Is there some way get "01" ?

Regards.

About this Entry

This page contains a single entry by klsh published on October 25, 2003 12:12 PM.

Weekly Summary Of Linux Kernel Traffic was the previous entry in this blog.

Old Versions Of Popular Software is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.