I need to enumerate the keys in the WScript.Shell.Environment object. It’s clear that if you already know the name of the key, you’re home free with:
Set oShell = WScript.CreateObject("WScript.Shell")
Debug.WriteLine "PATH=" & oShell.Environment("PATH")
…but if you want to list the keys, it looks like you’re out of luck! Is there a secret passageway somewhere?
The
WshEnvironmentobject is a collection, so you can enumerate it using VBScript’sFor Each ... Nextstatement:The output contains both environment variable names and values, like this: