Environment Property 

Returns the WshEnvironment object (a collection of environment variables).


object.Environment ([strType]) 

Arguments

  • object
    WshShell object.
  • strType
    Optional. Specifies the location of the environment variable.

Remarks

The Environment property contains the WshEnvironment object (a collection of environment variables). If strType is supplied, it specifies where the environment variable resides with possible values of System, User, Volatile, or Process. If strType is not supplied, the Environment property returns different environment variable types depending on the operating system.

Type of Environment Variable Operating System

System

Microsoft Windows NT/2000

Process

Windows 95/98/Me

Note

For Windows95/98/Me, only one strType is permitted — Process.

The following table lists some of the variables that are provided with the Windows operating system. Scripts can access environment variables that have been set by other applications.

Note

None of the following variables are available from the Volatile type.

Name Description System User Process (NT/ 2000) Process (98/ME)

NUMBER_OF_PROCESSORS

Number of processors running on the machine.

X

-

X

-

PROCESSOR_ARCHITECTURE

Processor type of the user's workstation.

X

-

X

-

PROCESSOR_IDENTIFIER

Processor ID of the user's workstation.

X

-

X

-

PROCESSOR_LEVEL

Processor level of the user's workstation.

X

-

X

-

PROCESSOR_REVISION

Processor version of the user's workstation.

X

-

X

-

OS

Operating system on the user's workstation.

X

-

X

-

COMSPEC

Executable file for the command prompt (typically cmd.exe).

X

-

X

X

HOMEDRIVE

Primary local drive (typically the C drive).

-

-

X

-

HOMEPATH

Default directory for users (typically \users\default in Windows 2000).

-

-

X

-

PATH

PATH environment variable.

X

X

X

X

PATHEXT

Extensions for executable files (typically .com, .exe, .bat, or .cmd).

X

-

X

-

PROMPT

Command prompt (typically $P$G).

-

-

X

X

SYSTEMDRIVE

Local drive on which the system directory resides (typically c:\).

-

-

X

-

SYSTEMROOT

System directory (for example, c:\winnt). This is the same as WINDIR.

-

-

X

-

WINDIR

System directory (for example, c:\winnt). This is the same as SYSTEMROOT.

X

-

X

X

TEMP

Directory for storing temporary files (for example, c:\temp).

-

X

X

X

TMP

Directory for storing temporary files (for example, c:\temp).

-

X

X

X

Example

The following code retrieves the system environment variable NUMBER_OF_PROCESSORS.

Set WshShell = WScript.CreateObject("WScript.Shell")

Set WshSysEnv = WshShell.Environment("SYSTEM")

WScript.Echo WshSysEnv("NUMBER_OF_PROCESSORS")
var WshShell = WScript.CreateObject("WScript.Shell");

var WshSysEnv = WshShell.Environment("SYSTEM");

WScript.Echo(WshSysEnv("NUMBER_OF_PROCESSORS"));

Applies To:

WshShell Object

See Also

Reference

WshEnvironment Object