WSH » WshEnvironment » Item

Syntax:
object[.Item] (strName)
strName
Receives a string containing the name of an environment variable.

The Item property is the default property of the WshEnvironment object. It takes a single argument of type String, and returns the value of the environment variable with the specified name, or the empty string if no such environment variable exists in the collection. When used on the left hand side of an assignment operation, this property adds a new environment variable with the specified name, and assigns it the specified value.

Examples

Code:
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Environment("SYSTEM")("MyVar1") = "hello"
objShell.Environment("SYSTEM").Item("MyVar2") = "world"
WScript.Echo objShell.Environment("SYSTEM").Item("MyVar1"), _
    objShell.Environment("SYSTEM")("MyVar2")
Output:
hello world
Explanation:

This VBScript code adds two new environment variables and then displays their values. The example also illustrates the two different forms of syntax available for this default property.

Language(s): VBScript

See Also: