List all environment variables on a computer

Script from Microsoft. Lists all environment variables on a computer.

import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_Environment")
for objItem in colItems:
    print "Caption: ", objItem.Caption
    print "Description: ", objItem.Description
    print "Install Date: ", objItem.InstallDate
    print "Name: ", objItem.Name
    print "Status: ", objItem.Status
    print "System Variable: ", objItem.SystemVariable
    print "User Name: ", objItem.UserName
    print "Variable Value: ", objItem.VariableValue

2 Replies to “List all environment variables on a computer”

  1. My IDLE python shell doesn’t have the requisite module. Is “import os” a substitute? If so how do I redefine some of the variables?

    1. I don`t understand. There is no “import os” in the script. If it`s a general question, the os-module is available in the Python standard package.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.