How to List Environmental Variables in Windows
You may never see an environment variable, but Windows and important applications use them to keep your computer running behind the scenes. An application, for instance, may query an environment variable such as "%userprofile%" to obtain the location of your profile folder. You can view a list of environment variables by creating a short VBS program that obtains this information.
Instructions
-
-
1
Open Notepad and paste the following VBS code into a new document:
winObjectA = "winmgmts:"
winObjectB = "{impersonationLevel=impersonate}!\\." & "\root\cimv2"
win32Query = "Select * from Win32_Environment"Set winObject = GetObject(winObjectA & winObjectB)
Set results = winObject.ExecQuery(win32Query)
For Each result in results
resultString = "User Name=" & result.UserName & " Name=" & result.Name & " Value=" & result.VariableValue & " Description=" & result.Description
Wscript.Echo resultString
Wscript.Echo " "
NextThe first three lines of code set up a select statement needed to retrieve the variable information. The next two statements create an instance of Winmgmts and use GetObject to store the results of the query in the variable named results. The final statements loop through the results and display the properties of each environmental variable returned from the query.
-
2
Press "Ctrl" and "S" to open Notepad's Save As window. Type "%userprofile%" in the address bar that appears at the top of the window and press "Enter." Windows opens your user profile folder. Type a name for the file in the File Name text box. Append ".vbs" to the end of the file name. This tells Windows that it's a VBS file. Click "Save" to save the file to your profile folder.
-
-
3
Click the Windows orb and type "cmd" in the search box. Press "Enter" to open the Command window. Type "Cscript xyz" into the window. Replace "xyz" with the name of the VBS file you saved and press "Enter." Windows displays the property information for all your environmental variables.
-
4
Type "Cscript xyz > myFile.txt" in the Command window to send the information to a file instead of the Command Window screen. Replace "xyz" with the name of your VBS file, and replace "myFile.txt" with the name of the file you'd like to store the results. Press "Enter." Windows creates the file if it doesn't exist.
-
1