Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Collapse the table of content
Expand the table of content

Win32_Environment class

The Win32_EnvironmentWMI class represents an environment or system environment setting on a Windows computer system. Querying this class returns environment variables found in:




The following syntax is simplified from Managed Object Format (MOF) code and includes all of the inherited properties. Properties are listed in alphabetic order, not MOF order.


[Dynamic, Provider("CIMWin32"), Privileges("SeRestorePrivilege"), UUID("{8502C4D2-5FBB-11D2-AAC1-006008C78BC7}"), SupportsCreate, CreateBy("PutInstance"), SupportsDelete, DeleteBy("DeleteInstance"), SupportsUpdate, AMENDMENT]
class Win32_Environment : CIM_SystemResource
  string   Caption;
  string   Description;
  datetime InstallDate;
  string   Name;
  string   Status;
  boolean  SystemVariable;
  string   UserName;
  string   VariableValue;


The Win32_Environment class has these types of members:


The Win32_Environment class has these properties.

Data type: string
Access type: Read-only

Short description of the object.

Data type: string
Access type: Read-only

Description of the object.

Data type: datetime
Access type: Read-only

Object was installed. This property does not require a value to indicate that the object is installed.

Data type: string
Access type: Read/write
Qualifiers: Override ("Name") , key, MappingStrings ("Win32Registry|System\\CurrentControlSet\\Control\\Session Manager\\Environment")

Character string that specifies the name of a Windows-based environment variable. By specifying the name of a variable that does not yet exist, an application creates a new environment variable.

Example: "Path"

Data type: string
Access type: Read-only

Current status of the object. Various operational and nonoperational statuses can be defined. Operational statuses include: "OK", "Degraded", and "Pred Fail" (an element, such as a SMART-enabled hard disk drive, may be functioning properly but predicting a failure in the near future). Nonoperational statuses include: "Error", "Starting", "Stopping", and "Service". The latter, "Service", could apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work. Not all such work is online, yet the managed element is neither "OK" nor in one of the other states.

The values are:

"Pred Fail"
"No Contact"
"Lost Comm"
Data type: boolean
Access type: Read-only
Qualifiers: MappingStrings ("Win32Registry|System\\CurrentControlSet\\Control\\Session Manager\\Environment")

Indicates whether the variable is a system variable. A system variable is set by the operating system, and is independent from user environment settings.

Data type: string
Access type: Read-only
Qualifiers: key, MaxLen (260) , MappingStrings ("Win32Registry|System\\CurrentControlSet\\Control\\Session Manager\\Environment")

Name of the owner of the environment setting. It is set to <SYSTEM> for settings that are specific to the Windows-based system (as opposed to a specific user) and <DEFAULT> for default user settings.

Example: "JSmith"

Data type: string
Access type: Read/write
Qualifiers: MappingStrings ("Win32Registry|System\\CurrentControlSet\\Control\\Session Manager\\Environment")

Placeholder variable of a Windows-based environment variable. Information like the file system directory can change from computer to computer. The operating system substitutes placeholders for these.

Example: "%SystemRoot%"


The Win32_Environment class is derived from CIM_SystemResource. You can use this class to find the paths of special folders such as the System folder or Program files on a remote machine. Some examples are: windir, systemroot, programfiles, and userprofile. Win32_environment basically returns what can be found in:




The calling process that uses this class must have the SE_RESTORE_NAME privilege on the computer in which the registry resides. For example, if you enumerate this class on the local computer, the account under which your application runs must have this privilege. For more information, see Executing Privileged Operations.


The List Environment Variables on a Computer Perl sample uses WMI to return information about all the environment variables on a computer.

The following VBScript code example enumerates the environment variables on the local computer.

strComputer = "."
Set objWMIService = GetObject( _
    "winmgmts:\\" & strComputer & "\root\cimv2")
Set colVar = objWMIService.ExecQuery( _
    "Select * from Win32_Environment")
For Each objVar in colVar
    Wscript.Echo "Description: " & objVar.Description _
        & VBNewLine & "Name: " & objVar.Name _
        & VBNewLine & "System Variable: " _
        & objVar.SystemVariable & VBNewLine _
        & "User Name: " & objVar.UserName & VBNewLine _
        & "Variable Value: " & objVar.VariableValue 

The following VBScript code example changes an environment variable named BUILD_TYPE to a value input by the user. The script assumes that the BUILD_TYPE variable already exists. If it does not exist then the script ends. The input value is checked: it must be either "Build1", "Build2", or "Build3", and no other value is accepted. The VBScript UCase function makes the input case-insensitive. If what is typed in is not one of the three acceptable values, the script ends.

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject( _
    "winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery( _
    "Select * from Win32_Environment")
Found = False
For Each objItem in colItems
    If objItem.Name = "BUILD_TYPE" Then
    Found = True
    Change = UCase(InputBox("BUILD_TYPE currently = " _
        & objItem.VariableValue & VBNewLine _
        & "Change options are Build1, Build2, Build3 "))
        If UCase(Change) = "BUILD1" OR _
            Change = "BUILD2" OR _
            Change = "BUILD3" Then
            objItem.VariableValue = Change
        WScript.Echo "BUILD_TYPE changed to " _
            & objItem.VariableValue
        WScript.Echo "No input or unacceptable input." _
            & " No change to BUILD_TYPE"
        End If
    End If
If Found = False Then
    WScript.Echo "User-defined environment" _
        & " variable BUILD_TYPE not found."
End If


Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2003







See also

Operating System Classes



© 2015 Microsoft