Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


January 29, 2002

What environment variables are available in Windows?

RSS
Subscribe to Windows IT Pro | See More Configuration Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

A. You can use environment variables to gain information about a system. For a complete list of environment variables available in Windows, see the following table:

Table 1: Environment Variables

ALLUSERSPROFILE Local returns the location of the All Users Profile.
APPDATA Local returns the location where applications store data by default.
CD Local returns the current directory string.
CMDCMDLINE Local returns the exact command line used to start the current cmd.exe.
CMDEXTVERSION System returns the version number of the current Command Processor Extensions.
COMPUTERNAME System returns the name of the computer.
COMSPEC System returns the exact path to the command shell executable.
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 System returns the error code of the most recently used command. A non-0 value usually indicates an error.
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 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 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.
LOGONSEVER Local returns the name of the domain controller that validated the current logon session.
NUMBER_OF_PROCESSORS System specifies the number of processors installed on the computer.
OS System returns the OS name. Windows XP and Windows 2000 display the OS as Windows_NT.
PATH System specifies the search path for executable files.
PATHEXT System returns a list of the file extensions that the OS considers to be executable.
PROCESSOR_ARCHITECTURE System returns the processor's chip architecture. Values: x86, IA64.
PROCESSOR_IDENTFIER System returns a description of the processor.
PROCESSOR_LEVEL System returns the model number of the computer's processor.
PROCESSOR_REVISION System returns the revision number of the processor.
PROMPT Local returns the command-prompt settings for the current interpreter. Cmd.exe generates this variable.
RANDOM System returns a random decimal number between 0 and 32767. Cmd.exe generates this variable.
SYSTEMDRIVE System returns the drive containing the Windows root directory (i.e., the system root).
SYSTEMROOT System returns the location of the Windows root directory.
TEMP or 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 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 Local returns the name of the domain that contains the user's account.
USERNAME Local returns the name of the user currently logged on.
USERPROFILE Local returns the location of the profile for the current user.
WINDIR System returns the location of the OS directory

To access these environment variables, you must place a percentage symbol (%) before and after the variable. For example,

echo %PROCESSOR_ARCHITECTURE%
x86 
will display the processor type (but still won't display Intel's ia64 platform). Some environment variables are available only in later OSs (e.g., %RANDOM% is not available in Windows NT 4.0).

End of Article



Reader Comments
Well, in xp, set USERPROFILE=D:\Somefile works only during the current session. Logging out and in resets the environment variable to default. I don't know how to fix that.

Rendall March 15, 2004


Most excellent article! Looked all over for this info.

Darrel Doehr May 26, 2004


Perfect

HarryC0der July 20, 2004 (Article Rating: )


finally - the list of variables

I've been looking for this for quite a while...

Anonymous User November 01, 2004 (Article Rating: )


Wish there were more.

Anonymous User November 16, 2004


USERPROFILE=%HOMEDRIVE%%HOMEPATH%


Anonymous User November 18, 2004


happiness.

Anonymous User January 10, 2005 (Article Rating: )


i have set reg values for env so that bat files can use them but the pc needs to be rebooted before set can see them from cmd prompt,who can i force a reread from a vbs script, is there a reg reread similar to reg read/regwrite

Anonymous User February 07, 2005


How would I store the value of an environment variable into....say a text file?

Anonymous User February 23, 2005


How would I store the value of an environment variable into....say a text file?

Anonymous User February 23, 2005 (Article Rating: )


 See More Comments  1   2   3 

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Kon-Boot Lets You Bypass Logon for Windows and Linux

Kon-Boot looks like a very interesting tool since it can get you into a system without having to logon first. ...

Google to Take On Windows with New OS

It's official: Google will compete head-to-head with Microsoft's dominant Windows OS with a new system called Google Chrome OS. Based on the Google Chrome browser and not its previous OS effort, the smart phone-based Android system, Google Chrome OS will ...

Q. How can I continually check a performance counter from Windows PowerShell?

...


Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

Related Events WinConnections and Microsoft® Exchange Connections

Cutting Costs with Client Management

7 Ways To Get More From Your SharePoint Deployment Now

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format

Test Drive IT Solutions and Get Free Music Downloads
Solve your toughest IT problems with these free downloads and receive 5 free music downloads!


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement | Reprints and Licensing