Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I view my SYSTEM environment variables in a command prompt?

I've seen in multiple stack overflow posts that LOCAL path variables can be seen by using:

echo %Path%

But I'd like to view my SYSTEM path variables found in (Windows 10):

Control Panel > System and Security > System > Advanced system settings > Environment Variables... > System variables

Does anyone know how to view these from the command line? If this has already been answered for system variables, please point me in that direction.

EDIT: I'm running a line that checks to see if a variable exists, if it doesn't, I am resetting the value of Path to all of the old variables, plus the new one. I need only the system variables and no other variables, because when I store my current variables, plus the new one, I don't want any other variables to be appended that shouldn't belong in my system environment variables.

e.x. if I were to use echo %Path% or set %Path% I might be storing local variables in my system variables. I'd rather not do that.

like image 693
Kyle Stoflet Avatar asked Jan 26 '26 07:01

Kyle Stoflet


1 Answers

This lists the four types of variables. To use in a console

cscript //nologo C:\pathto\script.vbs

Note there are variables that aren't listed, these are listed in help for set - type set /?.

Set WshShell = CreateObject("WScript.Shell")


Set wshsysEnv = WshShell.Environment("SYSTEM")
Wscript.echo "System"
For Each S In wshsysEnv
    WScript.echo S 
Next
Wscript.echo ""

Set wshsysEnv = WshShell.Environment("Volatile")
Wscript.echo "Volatile"
For Each S In wshsysEnv
    WScript.echo S 
Next
Wscript.echo ""

Set wshsysEnv = WshShell.Environment("User")
Wscript.echo "User"
For Each S In wshsysEnv
    WScript.echo S 
Next
Wscript.echo ""

Set wshsysEnv = WshShell.Environment("Process")
Wscript.echo "Process"
For Each S In wshsysEnv
    WScript.echo S 
Next
Wscript.echo ""

To get the two paths (user path is blank on a new installation of windows, but software may change it)

Set wshsysEnv = WshShell.Environment("User")
Wscript.echo "User"
For Each S In wshsysEnv
    If lcase(left(S,5)) = LCase("PATH=") then WScript.echo S 
Next
Wscript.echo ""

Set wshsysEnv = WshShell.Environment("System")
Wscript.echo "System"
For Each S In wshsysEnv
    If lcase(left(S,5)) = LCase("PATH=") then WScript.echo S 
Next
Wscript.echo ""

To get just the system paths without "Path=" at the beginning, use this

Set WshShell = CreateObject("WScript.Shell")

Set wshsysEnv = WshShell.Environment("System")
For Each S In wshsysEnv
    If lcase(left(S,5)) = LCase("PATH=") then WScript.echo right(S,Len(S)-5)
Next
Wscript.echo ""

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!